Daily Challenge #42

I decided to post daily challenge after seeing that nobody has posted today’s challenge :innocent:

Convert content uri to path uri

Content URI : When we pick a file using activity starter it returns a uri which is not actual and needs to be converted to an actual path
Usage: Not much usage

Learn More about content/android uri

Path URI: It is an actual path to a file
Usage: Used mostly in development

Learn more about path/file Uri

Notes

  • You can not use any component (only in-built components are allowed)
  • You can not use any extension for it like TaifunFile , FileTools , etc

Examples

1:

content://com.android.externalstorage.documents/document/primary%3AAndroid%2Fdata%2Fcom.sunny.notez%2Ffiles%2Ftestt.txt

to

/storage/emulated/0/Android/data/com.sunny.notez/files/testt.txt

2:

content://com.android.externalstorage.documents/document/primary%3ADCIM%2FSharedFolder%2Favtar.png

to

/storage/emulated/0/DCIM/SharedFolder/avtar.png

3:

content://com.android.externalstorage.documents/document/primary%3ADCIM%2FSharedFolder%2Fsample.pdf

to

/storage/emulated/0/DCIM/SharedFolder/sample.pdf

4:

content://com.android.externalstorage.documents/document/primary%3AMy%20Documents%2FDownloads%2Fapp_inventor_1558186508733.tmp

to

/storage/emulated/0/My Documents/Downloads/app_inventor_1558186508733.tmp

Quite easy if you focus at content uri

4 Likes

:thinking::thinking::thinking::thinking::thinking:

Kode should be made using in built blocks.

see here:

You should look at examples :wink:

You mean to select any file type (jpg, txt, mp3, …)?
This requires only a few adjustments.

Nope! I was talking about value returning procedure and to remove components as mentioned in first post:

Anyway,
Your solution is quite correct.