Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.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
Android-获取SD卡上图像的Uri_Android_Android Intent_Uri - Fatal编程技术网

Android-获取SD卡上图像的Uri

Android-获取SD卡上图像的Uri,android,android-intent,uri,Android,Android Intent,Uri,我在图库中有指向.jpg的绝对路径。 如何获取此图像的“content://”Uri,以便像这样使用此Uri: Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); 我需要启动此意图,以便查看图像。 只有图像的绝对路径时,如何获取uri?首先,您需要从SD卡读取文件 见: 然后调用File.toUri()方法从文件中检索URI Intent intent = new Intent(Intent

我在图库中有指向.jpg的绝对路径。 如何获取此图像的“content://”Uri,以便像这样使用此Uri:

Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
我需要启动此意图,以便查看图像。
只有图像的绝对路径时,如何获取uri?

首先,您需要从SD卡读取文件

见:

然后调用File.toUri()方法从文件中检索URI

Intent intent = new Intent(Intent.ACTION_VIEW, yourFile.toURI());
startActivity(intent);

谢谢你,但它不能正常工作。首先,有一个错误,因为Intent()构造函数的第二个参数应该是android.net.Uri,它是java.net.Uri。另外,方法yourFile.toUri()返回文件:/URI,而我想要的是内容:/URI。
Intent intent = new Intent(Intent.ACTION_VIEW, yourFile.toURI());
startActivity(intent);