Android - 在默认图库应用程序中从drawable打开图像

时间:2013-01-25 15:54:02

标签: java android

我正在开发具有多个图像视图的应用, 当我点击图像我希望它通过Android默认库图像选择器打开。 我试过这样的方式:

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

但它不起作用,我得到例外: android.content.ActivityNotFoundException:找不到处理Intent的Activity {act = android.intent.action.VIEW dat = android.resource://com.example.demo/2130837505 typ = image / *}

1 个答案:

答案 0 :(得分:3)

这是因为您的设备上没有能够使用Uri方案查看位于android:resource://的图像的活动。如果我不得不猜测,大约99%的Android设备会遇到类似的问题。

编写自己的图像查看器,或将图像移动到第三方应用更有可能支持的位置,例如您自己的ContentProvider或本地文件。