从图库中选择图像并在ImageView上显示它,在Nexus 5上发布 [英] Select Image From Gallery And Display It On ImageView, Issue On Nexus 5

查看:133
本文介绍了从图库中选择图像并在ImageView上显示它,在Nexus 5上发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常奇怪的问题,我希望用户选择一个图像并在ImageView上显示,该代码在我的小米mi52(V4.1.1)和我的小米MiPad(V4.4.4)上完美运行,但它完全是在我的Nexus 5(V5.0)上失败了。

I have a very weird issue, I want the user to select an image and display it on a ImageView, the code works perfectly on my Xiaomi mi52 (V4.1.1) and my Xiaomi MiPad (V4.4.4) but it's totally failed on my Nexus 5 (V5.0).

public class CreateContactActivity extends Activity {

    private ImageView imgProfile;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_create_contact);
        imgProfile = (ImageView)findViewById(R.id.imgProfileIV);
    }

    public void ImageProfile(View view) {
        Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
        photoPickerIntent.setType("image/*");
        startActivityForResult(photoPickerIntent, 100);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
        super.onActivityResult(requestCode, resultCode, imageReturnedIntent);

        switch(requestCode) {
            case 100:
                if(resultCode == RESULT_OK){
                    Uri selectedImage = imageReturnedIntent.getData();
                    imgProfile.setImageURI(selectedImage);
                }
           }
    }
}

布局activity_create_contact.xml:

Layout activity_create_contact.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    tools:context="${relativePackage}.${activityClass}" >

    <ImageView
        android:id="@+id/imgProfileIV"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_action_person"
        android:onClick="ImageProfile" />


</LinearLayout>

在LogCat上我收到以下错误:

On LogCat I get these errors:

12-10 15:33:18.348 D/skia﹕ --- SkImageDecoder::Factory returned null
12-10 15:33:18.350 I/System.out﹕ resolveUri failed on bad bitmap uri: content://media/external/images/media/72

奇怪这只是在我的Nexus 5上,而不是在小米设备上。我正在寻找,但我不明白问题出在哪里。

The weird this is it's just on my Nexus 5, not on the Xiaomi devices. I'm looking and looking but I don't understand where is the problem.

感谢您的帮助。

推荐答案

结果的差异可能来自您在不同平台上选择的选择器。

The difference in result may come from the "picker" you chose on different platform.

您应该尝试控制通过安装相同的文件资源管理器应用程序作为选择器进行实验,以便我们可以确保问题来自Android版本的差异

You should try to do control experiment by installing same file explorer app as picker so that we can make sure the problem comes from difference in Android version

这篇关于从图库中选择图像并在ImageView上显示它,在Nexus 5上发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆