Can I get Uri of image file from its name?

前端 未结 2 1771
孤城傲影
孤城傲影 2021-02-05 15:08

There are some image files, and I want to get Uri of these image files. In my code, I only know path and file name of image files. How can I get Uri from its path and file name?

2条回答
  •  南笙
    南笙 (楼主)
    2021-02-05 15:25

    If you have a File, you can always convert it to a URI:

    File file = new File(path + File.pathSeparator + filename);
    URI uri = file.toURI();
    

    Or, if you want to use the Android Uri class:

    Uri uri = Uri.fromFile(file);
    

提交回复
热议问题