16

in my app i let the user select an image from the gallery and had no problems doing this pre 4.2 but now when I select an image that is synced from my google+ account which i guess is a Picasa image I get this error

11-25 20:31:52.508: E/AndroidRuntime(17387): java.lang.RuntimeException: An error occured while executing doInBackground()
11-25 20:31:52.508: E/AndroidRuntime(17387):    at android.os.AsyncTask$3.done(AsyncTask.java:299)
11-25 20:31:52.508: E/AndroidRuntime(17387):    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
11-25 20:31:52.508: E/AndroidRuntime(17387):    at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
11-25 20:31:52.508: E/AndroidRuntime(17387):    at java.util.concurrent.FutureTask.run(FutureTask.java:239)
11-25 20:31:52.508: E/AndroidRuntime(17387):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
11-25 20:31:52.508: E/AndroidRuntime(17387):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
11-25 20:31:52.508: E/AndroidRuntime(17387):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
11-25 20:31:52.508: E/AndroidRuntime(17387):    at java.lang.Thread.run(Thread.java:856)
11-25 20:31:52.508: E/AndroidRuntime(17387): Caused by: java.lang.SecurityException: Permission Denial: opening provider com.android.gallery3d.provider.GalleryProvider from ProcessRecord{42817d60 17387:com.tyczj.bowling/u0a10087} (pid=17387, uid=10087) requires com.google.android.gallery3d.permission.GALLERY_PROVIDER or com.google.android.gallery3d.permission.GALLERY_PROVIDER
11-25 20:31:52.508: E/AndroidRuntime(17387):    at android.os.Parcel.readException(Parcel.java:1425)
11-25 20:31:52.508: E/AndroidRuntime(17387):    at android.os.Parcel.readException(Parcel.java:1379)
11-25 20:31:52.508: E/AndroidRuntime(17387):    at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:2530)
11-25 20:31:52.508: E/AndroidRuntime(17387):    at android.app.ActivityThread.acquireProvider(ActivityThread.java:4460)
11-25 20:31:52.508: E/AndroidRuntime(17387):    at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2002)
11-25 20:31:52.508: E/AndroidRuntime(17387):    at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1101)
11-25 20:31:52.508: E/AndroidRuntime(17387):    at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:708)
11-25 20:31:52.508: E/AndroidRuntime(17387):    at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:614)
11-25 20:31:52.508: E/AndroidRuntime(17387):    at android.content.ContentResolver.openInputStream(ContentResolver.java:449)
11-25 20:31:52.508: E/AndroidRuntime(17387):    at com.tyczj.bowling.BowlersListFragment$LoadImage.doInBackground(BowlersListFragment.java:390)
11-25 20:31:52.508: E/AndroidRuntime(17387):    at com.tyczj.bowling.BowlersListFragment$LoadImage.doInBackground(BowlersListFragment.java:1)
11-25 20:31:52.508: E/AndroidRuntime(17387):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
11-25 20:31:52.508: E/AndroidRuntime(17387):    at   java.util.concurrent.FutureTask.run(FutureTask.java:234)
11-25 20:31:52.508: E/AndroidRuntime(17387):    ... 4 more

So I put in com.google.android.gallery3d.permission.GALLERY_PROVIDER in my manifest but I still get that error so what else do I have to do? This is the first time I am seeing this and have found no information online about this issue.

If this is going to be a problem can I just have the gallery show images that are on the device and exclude Picasa images?

Like I said I did not have this problem before 4.2 or maybe it has to do with a recent google+ update?

EDIT:

It only gives me the error after i get out of the app and try to start it again. So if I am in the app and select the image to show the first time it works fine until I exit. I store the Uri in my database to load when it starts

here is my Manifest permissions

<uses-permission android:name="com.tyczj.bowling.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="com.google.android.gallery3d.permission.GALLERY_PROVIDER" />
<uses-permission android:name="android.permission.INTERNET" />
tyczj
  • 71,600
  • 54
  • 194
  • 296
  • 1
    I'm having the same problem. As far as I can tell, this is part of the new fine-grained "URI permissions" - see http://developer.android.com/guide/topics/security/permissions.html#uri for details. When I acquire the URI the first time, the app has a one-time permission to read that URI. When the app starts again however, it no longer has permission to read that stored URI. I guess I could save the image to internal storage when I first acquire the URI, and then read that file instead. That seems clunky though - ideally, we would just re-use the URI and get the permission to read from it. – Daniel Schuler Nov 26 '12 at 04:10
  • I am probably going to just check the returned uri to see if the image is from that specific content provider and tell the user they cant use this image – tyczj Nov 26 '12 at 13:45

2 Answers2

2

I had a similar problem implementing ACTION_SEND and ACTION_SEND_MULTIPLE in my app (also in Android 4.2.x). If I went to the gallery, selected one or more Picasa images, then chose "share", then chose my app from the picker, my app would throw the same SecurityException as above. Any attempt to use a query/load method from ContentResolver would throw.

I also tried adding the GALLERY_PROVIDER permission, but it didn't help (also, I looked in Instagram's manifest; It doesn't have this permission listed).

Eventually, on a whim, I took out android:launchMode="singleTask" from my entity, and low and behold, everything worked.

I have no idea why a single-task app would be barred from sharing in this way. Bug? Feature?

jules
  • 514
  • 5
  • 8
0

what I ended up doing to solve this is save the image locally and use the uri of that image anytime I need the image

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent){
        super.onActivityResult(requestCode, resultCode, imageReturnedIntent); 

            if(resultCode == Activity.RESULT_OK && requestCode == 1){  
                Uri selectedImage = imageReturnedIntent.getData();
                new SaveImage().execute(selectedImage.toString());

        }
    }

public class SaveImage extends AsyncTask<String,Void,Void>{

        @Override
        protected Void doInBackground(String... params) {
            String uri = params[0];

            if(uri != null && !uri.equals("")){
                ContextWrapper cw = new ContextWrapper(getActivity());
                File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
                File mypath=new File(directory,String.valueOf(bowlerID)+"profile.jpg");
                FileOutputStream fos = null;
                InputStream input = null;
                try { 
                    fos = new FileOutputStream(mypath);
                    input = getActivity().getContentResolver().openInputStream(Uri.parse(uri));
                    Bitmap bitmap = BitmapFactory.decodeStream(input);
                    if(bitmap != null){
                        if(bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos)){
                            ContentValues values = new ContentValues();
                            values.put(BowlersDB.PHOTO_URI, mypath.getAbsolutePath());
                            getActivity().getContentResolver().update(BowlersDB.CONTENT_URI, values,BowlersDB.ID+"="+bowlerID,null);
                        }
                    }
                    fos.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            return null;
        }

    }
tyczj
  • 71,600
  • 54
  • 194
  • 296