开发者社区 问答 正文

使用文件路径在gallery中打开一个图像

我在数据库中存储一个图像文件路径。现在使用它我想打开 gallery 中 SD Card 的图像。
我使用的下面的代码:
screenshot
出现的错误:
screenshot
如何处理这个问题?

展开
收起
蛮大人123 2016-02-18 11:48:26 1981 分享 版权
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪
    Intent newintent = new  Intent(android.content.Intent.ACTION_VIEW);
    newintent.setDataAndType(Uri.parse(file.getAbsolutePath().toString()), "image/*");
    newintent.setFlags(newintent.FLAG_ACTIVITY_NEW_TASK);
    try{
          FileExplorer.this.startActivity(newintent);
       }
    catch(android.content.ActivityNotFoundException e){
    Toast.makeText(this, "没有找到合适的应用打开文件",1).show();
    }
    2019-07-17 18:43:51
    赞同 展开评论
问答分类:
问答地址: