我正在创建一个应用程序,让用户从手机图库中挑选一张图片。对于 SD 卡上的图像,一切正常,但当用户从 Picassa 中选择图片时,应用程序崩溃。
调用画廊的代码:
Intent i = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, SELECT_FROM_GALLERY_ACTION);
接收图片代码:
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
File galeryFile = new File(filePath);
FileUtils.copyFile(galeryFile, imageFile);
processImage(imageFile);
错误:
08-30 14:51:04.268: E/ActivityThread(31379): Failed to find provider info for com.android.gallery3d.provider
08-30 14:51:04.278: E/AndroidRuntime(31379): FATAL EXCEPTION: main
08-30 14:51:04.278: E/AndroidRuntime(31379): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=4353, result=-1, data=Intent { dat=content://com.android.gallery3d.provider/picasa/item/5735585761449205042 flg=0x1 }} to activity {com.example.my_gallery_app/com.example.my_gallery_app.MainActivity}: java.lang.NullPointerException
空指针出现在线:
cursor.moveToFirst();
我读了这个解决方法。但评论并不乐观。我想限制画廊向用户显示 Facebook、Picassa 或其他图片,并让她只从 SD 卡中挑选图片。