【发布时间】:2014-12-10 14:37:44
【问题描述】:
我有一个非常奇怪的问题,我希望用户选择一个图像并将其显示在 ImageView 上,该代码在我的小米 mi52 (V4.1.1) 和我的小米 MiPad (V4.4.4) 上完美运行,但它完全在我的 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:
<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 上我收到以下错误:
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 上,而不是在小米设备上。我正在寻找和寻找,但我不明白问题出在哪里。
感谢您的帮助。
【问题讨论】:
-
在我的 Nexus 5 上运行良好
-
谢谢你的帮助,很奇怪,知道什么时候能出吗?
-
它会在您选择的任何图像上执行此操作吗?以及您使用什么应用来选择图像。
-
它什么都不显示,它删除了默认图像。我正在使用系统应用程序选择图像(我猜)。
-
我的意思是你会得到每张图片的错误
标签: android imageview onactivityresult