java - 使用文件路径在图库中打开图像

标签 java android eclipse

我的数据库中存储了一个图像文件路径。现在使用它我想在我的画廊中打开 SD 卡中的图像。我怎样才能做到这一点。我已经看到 Uri 的方法并使用了这个方法,但是我收到了错误

File file = new File(filename);
            Uri uri = Uri.fromFile(file);
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            intent.setType("image/*");
            startActivity(intent); /** replace with your own uri */

如何解决,

04-20 08:42:23.516: E/AndroidRuntime(16815): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///mnt/sdcard/My%20App/image_umxto_1.jpg }

最好的问候

最佳答案

Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.fromFile(new File(filename)), "image/*");
            startActivity(intent);

使用此代码并告诉我

关于java - 使用文件路径在图库中打开图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10239897/

相关文章:

java - 如何在Kotlin中换行?

java - 将 SQLite 与我的 Java EE 应用程序集成的正确方法是什么?

Eclipse 颠覆 "Connection Failed By Server"

c - Eclipse 在 C 项目中没有构建消息

java - 如何避免 java7 if 语句或使代码更具可读性

java - Elasticsearch GetResponse.getField 抛出 NullPointerException

java - android中动态内容的多语言支持?

android - 在 TextView 上使用 alpha 蒙版也会删除父 View alpha?

android - 调整 Windroy 窗口的大小

eclipse - 谁能解释Eclipse中项目资源管理器,包资源管理器和导航器之间的确切区别?