如何获得存储的SD卡一个图像的URI? [英] How to get the Uri of a image stored on the SDCARD?

查看:142
本文介绍了如何获得存储的SD卡一个图像的URI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要存储的SD卡一个图像的URI。

当我想获得存储在一个绘制图像的URI,我用这个和它的作品完美的:

  i.putExtra(Intent.EXTRA_STREAM,Uri.parse(android.resource://+ getPackageName()+/+ R.drawable.image));

但是,如果我想获得存储的SD卡一个图像的URI,我trye​​d这一点,它不工作,什么是错的:

  i.putExtra(Intent.EXTRA_STREAM,Uri.parse(到/ mnt / SD卡/ car.jpg));

请,有人可以告诉我怎么去存储在SD卡一个图像的正确URI?

感谢


解决方案

 字符串文件名=image.png;
字符串路径=到/ mnt / SD卡/+文件名;
 文件f =新的文件(路径); //
            乌里imageUri = Uri.fromFile(F);

I need to get the URI of a image stored on the SDCARD.

When i want to get the Uri of a image stored on drawable, i use this and it works perfect:

i.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.image));

But if i want to get the URI of a image stored on the SDCARD, i tryed with this, and it doesn't works, something is wrong:

i.putExtra(Intent.EXTRA_STREAM, Uri.parse("/mnt/sdcard/car.jpg"));

Please, can someone tell me how to get the correct uri of a image stored on the sdcard?

Thanks

解决方案

String filename = "image.png";
String path = "/mnt/sdcard/" + filename;
 File f = new File(path);  //  
            Uri imageUri = Uri.fromFile(f);     

这篇关于如何获得存储的SD卡一个图像的URI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆