Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android-在默认图库应用程序中从drawable打开图像_Java_Android - Fatal编程技术网

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

Java Android-在默认图库应用程序中从drawable打开图像,java,android,Java,Android,我正在开发一个有很多图像视图的应用程序, 当我点击图像时,我希望它通过安卓默认画廊图像选择器打开。 我试过这样做: String str = "android.resource://" + getPackageName() +"/"+R.drawable.wall1; Uri path = Uri.parse(str); Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndTy

我正在开发一个有很多图像视图的应用程序, 当我点击图像时,我希望它通过安卓默认画廊图像选择器打开。 我试过这样做:

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=image/*}

这是因为您的设备上没有任何活动能够使用
android:resource://
方案查看驻留在
Uri
上的图像。如果我不得不猜测的话,大约99%的安卓设备也会有类似的问题


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

这是因为您的设备上没有任何活动能够通过
android:resource://
方案查看驻留在
Uri
的图像。如果我不得不猜测的话,大约99%的安卓设备也会有类似的问题


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

您可能希望将可绘图文件写入临时SD卡位置?您可能希望将可绘图文件写入临时SD卡位置?