我正在开发一个将导入的照片存储到房间数据库中的应用程序,然后将它们全部显示在应用程序中。当我导入第一张图片时,一切都很好,但是当我重新启动它时,会导致此SecurityException,在该异常中,我使用AsyncTask访问会议室数据库中所有已保存的照片。
该错误不会在我的手机上发生,但会在模拟设备和备用手机上发生,并且我不确定这是什么原因。
我的问题是:为什么会发生此错误,我该如何解决?我已经尝试了我在StackOverflow上看到的大多数SecurityException修复程序,但似乎都没有用。
所有相关代码如下:
堆栈跟踪:
java.lang.SecurityException: Permission Denial: opening provider com.google.android.apps.photos.contentprovider.impl.MediaContentProvider from ProcessRecord{47792f1 13877:com.example.oskilla.geophotoapp/u0a91} (pid=13877, uid=10091) that is not exported from UID 10075
at android.os.Parcel.createException(Parcel.java:1942)
at android.os.Parcel.readException(Parcel.java:1910)
at android.os.Parcel.readException(Parcel.java:1860)
at android.app.IActivityManager$Stub$Proxy.getContentProvider(IActivityManager.java:4181)
at android.app.ActivityThread.acquireProvider(ActivityThread.java:5970)
at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2592)
at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1828)
at android.content.ContentResolver.query(ContentResolver.java:786)
at android.content.ContentResolver.query(ContentResolver.java:752)
at android.content.ContentResolver.query(ContentResolver.java:710)
at com.example.oskilla.geophotoapp.BitmapBuilder.createBitmap(BitmapBuilder.java:33)
at com.example.oskilla.geophotoapp.MapsActivity$FindPhotos.onPostExecute(MapsActivity.java:147)
at com.example.oskilla.geophotoapp.MapsActivity$FindPhotos.onPostExecute(MapsActivity.java:108)
at android.os.AsyncTask.finish(AsyncTask.java:695)
at android.os.AsyncTask.access$600(AsyncTask.java:180)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:712)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.am.ActivityManagerService.getContentProviderImpl(ActivityManagerService.java:12188)
at com.android.server.am.ActivityManagerService.getContentProvider(ActivityManagerService.java:12585)
at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:357)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3291)
at android.os.Binder.execTransact(Binder.java:731)
有问题的代码区域(无法获得光标):
String[] FILE = { MediaStore.Images.Media.DATA };
Cursor cursor = context.getContentResolver().query(photoUri, FILE, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(FILE[0]);
String ImageDecode = cursor.getString(columnIndex);
cursor.close();
bitmap = BitmapFactory.decodeFile(ImageDecode);
调用上述代码的代码(createBitmap):
for(PhotoEntity photo : photoEntities) {
System.out.println(photo.getImageLocation());
Uri bitmapUri = photo.getImageLocation();
System.out.println(bitmapUri.getPath() + " this is from findphotos");
Bitmap bitmap = BitmapBuilder.createBitmap(context, bitmapUri);
bitmap = BitmapBuilder.getBitmap(bitmap,
ExifConverter.getRealPathFromUri(context, photo.getImageLocation()), 200, 200);
}
非常感谢所有帮助。谢谢
答案 0 :(得分:1)
您需要在清单文件中添加此权限
<uses-permission android:name="com.google.android.apps.photos.permission.GOOGLE_PHOTOS"/>`