我目前正在开展一项活动,让用户从图库中选择一张图片,然后将该图片的URI放入SQLite数据库。
我有另一项活动,我将该URI用于在ImageView上显示。我在棒棒糖和老年人身上做得很好。但是当我拉出显示图像的活动时,任何更新的东西都会崩溃。
这是崩溃的LOGCAT行:
Caused by: java.lang.SecurityException: Permission Denial: opening provider com.google.android.apps.photos.contentprovider.MediaContentProvider from ProcessRecord{8193e94 13574:jeremy.com.wineofmine/u0a97} (pid=13574, uid=10097) that is not exported from uid 10044
这使它看起来像权限,但是我在清单中请求WRITE_EXTERNAL_STORAGE
和READ_EXTERNAL STORAGE
,以及在显示图像的活动上请求运行时的那些权限
以下是它崩溃的确切行(这是在显示图像的活动中):
bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageURI);
这是imageURI:
imageURI = Uri.parse(cursor.getString(cursor.getColumnIndexOrThrow(WineContract.WineEntry.COLUMN_WINE_IMAGE)));
//This code returns this: content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F62/ACTUAL/860591124
以下是相关位的代码。
这是打开图库的意图:
Intent intentGallery = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intentGallery, SELECT_IMAGE);
这是onActivityResult
方法。此方法的主要目标是将imageThumbail ImageView设置为缩略图,并将“photoURI”设置为所选图像的URI。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//This is if they choose an image from the gallery
if (requestCode == SELECT_IMAGE && resultCode == RESULT_OK) {
if (requestCode == SELECT_IMAGE) {
// Get the url from data
Uri selectedImageUri = data.getData();
if (null != selectedImageUri) {
// Get the path from the Uri
String path = getPathFromURI(selectedImageUri);
Log.i("ADDACTIVITY", "Image Path : " + path);
bitmap = null;
try {
bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImageUri);
} catch (IOException e) {
e.printStackTrace();
}
bitmapThumbnail = ThumbnailUtils.extractThumbnail(bitmap,175,175);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmapThumbnail.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byteArray = stream.toByteArray();
// Set the image in ImageView
imageThumbnail.setImageBitmap(bitmapThumbnail);
//Setting photoURI (which gets put into the database) as the gallery's image URI
photoURI = data.getData();
}
}
}
}
任何指向我可能做错的事情都会很棒。