为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

潇潇雨雨 2019-03-21 18:15:14
我在数据库中存储一个图像文件路径。现在使用它我想打开 gallery 中 SD Card 的图像。我使用的下面的代码: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 */出现的错误:06-05 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 }如何处理这个问题?
查看完整描述

2 回答

?
慕森王

TA贡献1777条经验 获得超3个赞

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-04-29
?
慕运维8079593

TA贡献1876条经验 获得超5个赞

Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.fromFile(new File(filename)), "image/*");
            startActivity(intent);
Use this code and tell me


查看完整回答
反对 回复 2019-04-29
  • 2 回答
  • 0 关注
  • 487 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号