Android Question Universal way to convert content:// url to file path ?

I know this question has been asked and also answered many times.
But sometimes some code works on specific paths and sometimes not.
I wanted a universal code and universal way to convert content:// url to file path that can be applicable for every content://type
Because I don't want to waste developers time daily by asking convert content://xyz or content://abc etc.

Suppose I have example content:// path
B4X:
 "/content:/com.android.externalstorage.documents/document/6759-130B%3ANew%20Text%20Document.txt"

I want to convert that it to this
B4X:
"storage/6759-130B%3ANew%20Text%20Document.txt"

ask if needed any additional info.Thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You should forget from getting the file path. The assumption that there is a file behind the content url is wrong. The assumption that even if there is a file, you have the permission to access it is also wrong.

You are getting a "link" to a remote resource. It can come from a database, an online service, or any other source.
 
Upvote 0
You are getting a "link" to a remote resource. It can come from a database, an online service, or any other source.
Oh ! So that's clearly mean universal way will not work in this scope.

Okay then suppose that content://xyz is an file path. How would you convert it then ?
I tried uri.localpath,uri.absolutepath, etc. It isnt 100% fine but it can give little match to what I want.

I guess com.android.externalstorage.documents points us that its path from external storage.

And also can you suggest me any file picker which can always return string file path Not content://xyz.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It will be easier to help you if you tell us why you need the file path.

And also can you suggest me any file picker which can always return string file path Not content://xyz.
No such thing.

Read my answer again. Even if you get the remote file path, you will not be able to access it.
 
Upvote 0
Top