How to load a Picasa image from URI?

余生颓废 提交于 2019-12-03 12:01:01

问题


I'm using ACTION_PICK intent to select an image from gallery. Some albums like "Posts", "Profile Photos", etc are marked with Picasa icon. For images from such albums I get a URI similar to this:

content://com.google.android.gallery3d.provider/picasa/item/5769844615871490082

I can load an image from this URI using ContentResolver and BitmapFactory with no problem:

final InputStream ist = context.getContentResolver().openInputStream(intent.getData());
final Bitmap bitmap = BitmapFactory.decodeStream(ist);

But I'm unable to load an image using stored URI after I restart the application. I'm getting this when decodeStream() is called:

03-11 12:34:56.502: A/libc(1172): Fatal signal 11 (SIGSEGV) at 0x00000408 (code=1), thread 1462 03-11 12:34:56.502:
    W/ActivityManager(478): Permission Denial: opening provider
    com.android.gallery3d.provider.GalleryProvider from
    ProcessRecord{41cdd220 1172:com.mycompany.myapp/u0a10085}
    (pid=1172, uid=10085) requires
    com.google.android.gallery3d.permission.GALLERY_PROVIDER or
    com.google.android.gallery3d.permission.GALLERY_PROVIDER

I tried to add

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

to the manifest file but it didn't help.

I think my problem is similar to this one, but no solution is given there, only a workaround. Is it possible to request a permission to access a stored URI?


回答1:


Try opening input stream like this

ContentResolver res = context.getContentResolver();
Uri uri = Uri.parse(intent.getData().toString());
res.openInputStream(uri);


来源:https://stackoverflow.com/questions/15330628/how-to-load-a-picasa-image-from-uri

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!