【发布时间】:2011-07-07 23:42:39
【问题描述】:
我在图库中有 .jpg 的绝对路径。 如何获取此图像的“内容://” Uri,以便我可以像这样使用此 Uri:
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
我需要启动此意图,以便查看图像。 当我只有图像的绝对路径时,如何获取 uri?
【问题讨论】:
标签: android android-intent uri
我在图库中有 .jpg 的绝对路径。 如何获取此图像的“内容://” Uri,以便我可以像这样使用此 Uri:
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
我需要启动此意图,以便查看图像。 当我只有图像的绝对路径时,如何获取 uri?
【问题讨论】:
标签: android android-intent uri
首先,您需要从 SDCard 中读取文件。
见:
reading a specific file from sdcard in android
http://developer.android.com/reference/java/io/File.html
File dir = Environment.getExternalStorageDirectory();
File yourFile = new File(dir, "path/to/the/file/inside/the/sdcard.ext");
然后调用 File.toUri() 方法从文件中检索 URI。
Intent intent = new Intent(Intent.ACTION_VIEW, yourFile.toURI());
startActivity(intent);
【讨论】: