0

Let me explain...

WHAT THE APP DOES

  1. An app allows the user to select an XML file from phone storage.
  2. The XML is opened through an ACTION_GET_CONTENT (changed that to ACTION_OPEN_DOCUMENT) Intent. With the XML Uri, a temporary File (the XML) is created in order for the app to read its contents (the app was prepared to receive and process Files not Uris.
  3. Among the XML data, there's an audio file path, which is always located where the XML was, such:
  • XML path: myStorage/myProject/example.xml
  • Audio file: myStorage/myProject/audio/audioSample.mp3
  1. After reading all the XML data, the user opens a new fragment where there's a MediaPlayer that has to play the "audioSample.mp3" file.
  2. The Media player was using some *app internal assets path as audio test files, like "content://" + "com.my.app/" + "audio/audioSample.mp3". The MediaPlayer also has a method that, instead of a "path string (as shown)", can use a "Uri" to play media.

THE PROBLEM

  • I've been unable to play the media when loaded from outside internal assets

WHAT I TRIED

  • Using the Uri and Path string options of the MediaPlayer
  • Hardcoding the Absolute Path string of the "audioSample"
  • Creating a new Uri from the XML original Uri, such as "content://interalStorage/myProject:audio/audioSample.mp3"
  • Encoding the last part of that Uri path (as I checked what system's Uri path looks like if the user selects the audioFile instead of the XML file)
  • Just copying that system Uri path of the audio file and hardcode it
  • When I finally got the correct (or what I think is correct) Uri path, like above, I got a No persistable permission grants found for UID 10476 and Uri content://com.android.externalstorage.documents/document/primary:myProject/audio/audioSample.mp3. Now, I looked that up and saw the takePersistableUriPermission option, but:
  1. It does not work well with fileChooserResultLauncher instead of old, deprecated, onActivityResult.
  2. It looks like it's just for one file, not the whole directory of "myProject"; so there's the option of ACTION_OPEN_DOCUMENT_TREE.

Any other approach aside from ACTION_OPEN_DOCUMENT_TREE? PS: Can I include that in the Intent or I must ask the user twice (one for selecting the XML the other for the Directory as a whole)?

4
  • You cannot take persistable uri permission with ACTION_GET_CONTENT. Use ACTION_OPEN_DOCUMENT instead. Commented Jul 12, 2023 at 19:14
  • With the XML Uri, a temporary File (the XML) is created That makes no sense. Even if you manage you got no read permission. Use the uri to open the file. Commented Jul 12, 2023 at 19:15
  • It looks like it's just for one file, not the whole directory of "myProject" Of course. You selected a file. Select directories with ACTION_OPEN_DOCUMENT_TREE. Commented Jul 12, 2023 at 19:17
  • @blackapps Yeap, sorry, I forgot to mention that I already tried that. I'm gonna edit. For the Temporary File it's because the app was designed to handle a File type (in several other parts of the code), that's why I need to handle it like that. Any approach aside from adding ACTION_OPEN_DOCUMENT_TREE? Thank you! Commented Jul 13, 2023 at 8:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.