0

I am working on an app which stores imported photos into a room database, with them all then being displayed within the app. It all works fine when I import my first picture, but then when I restart the, it results in this SecurityException, where I use an AsyncTask to access all the saved photos within the room database.

The error doesn't occur on my phone, but it does on the simulated device and my spare phone, and I am not sure of what the reason for that is.

My question is: Why is this error occurring, and how can I fix it? I have tried most of the fixes for SecurityException I have seen on StackOverflow, but none of them seem to work.

All relevant code is below:

Stack Trace:

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)

Area of code in question (failing at getting a cursor):

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);

The code that calls the above code (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);
}

All help is greatly appreciated. Thanks

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Oskilla
  • 13
  • 3
  • Check this [link](https://stackoverflow.com/questions/40438537/permission-denied-opening-provider-com-google-android-apps-photos-contentprovi). – Surender Kumar Dec 06 '18 at 10:56
  • @SurenderKumar it worked!! thanks so much haha!! i had taken a look at that post previously but was kinda lost. thanks again :) i was stumped previously because i didnt have any intents in the problem area. only just realised the issue was in the importing of the pictures.. – Oskilla Dec 06 '18 at 11:35

1 Answers1

1

You need to add this permision in your manifest file

<uses-permission android:name="com.google.android.apps.photos.permission.GOOGLE_PHOTOS"/>`
Asteroid
  • 718
  • 7
  • 21