0

我正在开发具有多个图像视图的应用程序,当我单击图像时,我希望它通过 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 { act=android.intent.action.VIEW dat=android.resource://com.example.demo/2130837505 typ= 的活动图片/* }

4

1 回答 1

4

这是因为您的设备上没有任何活动能够查看Uriandroid:resource://方案中的图像。如果我不得不猜测,大约 99% 的 Android 设备都会有类似的问题。

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

于 2013-01-25T15:55:52.820 回答