How to get the Uri of a image stored on the SDCARD?

前端 未结 2 828
无人及你
无人及你 2021-01-04 09:57

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.p         


        
2条回答
  •  没有蜡笔的小新
    2021-01-04 10:39

    Always use Environment.getExternalStorageDirectory() instead of hard coding the path of external storage directory. Because the path of external storage directory may be different in different API Levels.

    Try this:

    String fileName = "YourImage.png";
    String completePath = Environment.getExternalStorageDirectory() + "/" + fileName;
    
    File file = new File(completePath); 
    Uri imageUri = Uri.fromFile(file);
    

提交回复
热议问题