简体   繁体   English

Android-在默认库应用程序中从可绘制对象打开图像

[英]Android - open image from drawable in default gallery application

I'm working on app that have number of imageviews, when i click on the image i want it to open via android default gallery image picker. 我正在处理具有许多imageviews的应用程序,当我单击图像时,我希望它通过android默认画廊图像选择器打开。 i've tried in this way : 我已经尝试过这种方式:

String str = "android.resource://" + getPackageName() +"/"+R.drawable.wall1;

Uri path = Uri.parse(str);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(path, "image/*");
startActivity(intent);

but it doesn't work and i get exception: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=android.resource://com.example.demo/2130837505 typ=image/* } 但它不起作用,并且出现异常:android.content.ActivityNotFoundException:未找到处理意图的活动{act = android.intent.action.VIEW dat = android.resource://com.example.demo/2130837505 typ =图片/* }

That is because there is no activity on your device capable of viewing an image residing at a Uri with the android:resource:// scheme. 这是因为您的设备上没有任何活动能够使用android:resource://方案查看位于Uri的图像。 If I had to guess, ~99% of Android devices will have a similar problem. 如果我不得不猜测的话,大约99%的Android设备也会有类似的问题。

Either write your own image viewer, or move the image someplace that third-party apps are more likely to support, such as your own ContentProvider or a local file. 编写您自己的图像查看器,或将图像移动到第三方应用程序更可能支持的位置,例如您自己的ContentProvider或本地文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM