使用Universal-Image-Downloader下载图像时出现SecurityException

时间:2013-09-03 08:55:08

标签: java android universal-image-loader securityexception

在我的应用程序中,我使用通用图像下载器BaseImageDownloader类来同步加载gallery的内容。对于来自Imageloader.getInstance()。loadImage asyncronious函数的相同内容,它不会给出任何安全异常并加载图像,因为它是但是当我尝试使用BaseImageDownloader同时下载它时(也是Imageloader.getInstance()。loadImage()使得相同)我得到这个安全例外

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)

此外,我搜索了代码,您在配置或其他地方没有获得任何权限会导致什么原因?

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

3 个答案:

答案 0 :(得分:1)

这不是UIL see here的错误。根据{{​​3}}问题,您应该在首次加载时将图像加载到内部存储中,然后从那里读取图像。

答案 1 :(得分:0)

请为您的清单添加以下权限。

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

另请查看

How to grant temporary access to custom content provider using FLAG_GRANT_READ_URI_PERMISSION

答案 2 :(得分:0)

我添加了显示权限并且有效。但我不知道没有那个OIL怎么做?

<uses-permission android:name="com.google.android.gallery3d.permission.GALLERY_PROVIDER"/>