且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何获得存储的SD卡一个图像的URI?

更新时间:2022-10-20 20:10:03

 字符串文件名=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);