简体   繁体   中英

Get content:// Uri from File

I have a File object and I want to get its Uri, that looks like:

content://media/external/images/media/2683

I've tried the following code:

val uri = FileProvider.getUriForFile(activity, "${BuildConfig.APPLICATION_ID}.file_provider", pictureFile)

But I'm getting this:

content://my.package.name.file_provider/external_files/Pictures/photo-1574403815163.jpg

Is it possible to get the Uri I need?

UPD: The reason I want to get another Uri - I can't create File object from this Uri later.

val uri = FileProvider.getUriForFile(activity, "${BuildConfig.APPLICATION_ID}.file_provider", pictureFile)
val file = File(uri.path)

When I try to file.exists() I'm always getting false .

I can't create File object with this Uri

That's because you don't do that. Moreover, you don't need that. pictureFile is a File .

If your are creating file with actual path then you just concad the content:// to that path

Iam not sure this is correct method or not but i get that what you expected, Try this one

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM