1

On my application I used universal image downloader BaseImageDownloader class for syncronious loading contents of gallery.For the same content from Imageloader.getInstance().loadImage asyncronious function it does not gives any security exception and loads the image as it is ment to be but when I try to download it syncroniously using BaseImageDownloader (Also Imageloader.getInstance().loadImage() makes the same) i get this security Exception

09-02 18:49:43.971: W/System.err(4244): java.lang.SecurityException: Permission Denial: reading com.android.gallery3d.provider.GalleryProvider uri content://com.google.android.gallery3d.provider/picasa/item/5879964074642783474 from pid=4244, uid=10064 requires com.google.android.gallery3d.permission.GALLERY_PROVIDER, or grantUriPermission()
09-02 18:49:43.971: W/System.err(4244):     at android.os.Parcel.readException(Parcel.java:1425)
09-02 18:49:43.971: W/System.err(4244):     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
09-02 18:49:43.971: W/System.err(4244):     at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:148)
09-02 18:49:43.971: W/System.err(4244):     at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:617)
09-02 18:49:43.971: W/System.err(4244):     at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:717)
09-02 18:49:44.011: W/System.err(4244):     at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:614)
09-02 18:49:44.011: W/System.err(4244):     at android.content.ContentResolver.openInputStream(ContentResolver.java:449)
09-02 18:49:44.011: W/System.err(4244):     at com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStreamFromContent(BaseImageDownloader.java:156)
09-02 18:49:44.011: W/System.err(4244):     at com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStream(BaseImageDownloader.java:88)
09-02 18:49:44.011: W/System.err(4244):     at com.uploader.data.UploadImageData.decodeSampledBitmapFromStream(UploadImageData.java:80)

Also I searched the code and you do not take any permission for that on configuration or somewhere else what will be the cause?

public Bitmap decodeSampledBitmapFromStream(String path, int reqWidth, int reqHeight) throws IOException {
        BaseImageDownloader downloader = new BaseImageDownloader(getApplicationContext());
        InputStream stream = downloader.getStream(path, null);
        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(stream, new Rect(-1,-1,-1,-1), options);
        stream.close();
        options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

        options.inJustDecodeBounds = false;
        stream = downloader.getStream(path, null);
        Bitmap bitmap = BitmapFactory.decodeStream(stream, new Rect(-1,-1,-1,-1), options);
        stream.close();
        return bitmap;
    }
Philipp Jahoda
  • 50,880
  • 24
  • 180
  • 187
Rifat Döver
  • 494
  • 4
  • 17

3 Answers3

1

This is not a bug of UIL see here. According to this question you should load the image in internal storage on first loading and after that read the image from there.

Community
  • 1
  • 1
Sunny
  • 14,522
  • 15
  • 84
  • 129
0

Please add following permissoions to your mainfest.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

Also Please have a look at

How to grant temporary access to custom content provider using FLAG_GRANT_READ_URI_PERMISSION

Community
  • 1
  • 1
Anchit Mittal
  • 3,412
  • 4
  • 28
  • 48
  • Yes they are added universal image loader works correctly only when I tried to get Input stream with Base Image Downloader it gives error – Rifat Döver Sep 03 '13 at 09:11
  • What I can't understand UniversalImageLoader works correctly with same content image it is opening input stream and reading from content But When I directly try to use BaseImageDownloader for same content it fails.?? – Rifat Döver Sep 03 '13 at 09:18
0

I added permission to mainfest and it worked. But I dont know How UIL makes without that??

<uses-permission android:name="com.google.android.gallery3d.permission.GALLERY_PROVIDER"/>
Rifat Döver
  • 494
  • 4
  • 17
  • I don't think UIL fixed it: https://github.com/coomar2841/image-chooser-library/issues/8 . also , I think you can overcome this by saving the needed data into your app (maybe not the image, but just the metadata of it), and if there is a problem using the URIs, you can read using a filePath instead as a fallback. I'm not sure, but maybe you don't even need to get the metadata, and using the ExifInterface is enough (depending if it works and what are your needs). – android developer Nov 16 '14 at 08:35
  • Also, BTW, adding the permission doesn't seem to help. Try to do it with Picasa, as getting images from it using Uris. Sooner or later, you will get the same exception. – android developer Nov 16 '14 at 09:25