Android Question Permission Denial: opening provider com.android.providers.media.MediaDocumentsProvider

LucaMs

Expert
Licensed User
Longtime User
With reference to this post and the following ones...

MediaPlayer can successfully play the selected file, if newly selected.
If I save "directory" and file name, retrieve them from file and send them to the MediaPlayer, I get that error message, a permission is missing.

(... requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs)

How to do?
 

LucaMs

Expert
Licensed User
Longtime User
I'm attaching an example.

Select an audio file; MediaPlayer will play it, Dir and FileName will be saved as text file.

Start the app again. The two strings will be read and displayed. Pressing Play will call MediaPlayer's Play method, passing the two strings to it and then the app will crash.
 

Attachments

  • ContentChooserTest.zip
    16.6 KB · Views: 329
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
android documentation states:
"Use ACTION_OPEN_DOCUMENT if you want your app to have long term, persistent access to
documents owned by a document provider."
implying exactly what you've seen: first time works ok, subsequent attempts fail, apparently having lost
permission to access.
it looks like you'll need an intent with the abovementioned action to access the uri.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Sorry but this has nothing to do with it.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
It's a different matter, believe me.

EREEEEEEEEL ?
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Ok, but so... what's the solution for such an app?
It is not for me (as always now) but for another Italian member. Its operation is similar to the attached project.

Also, the question could be about any other file type (MIME).
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
i don't see why a different mime type cannot be specified
I meant to say...

Erel posts a link to that thread, that example, whenever it comes to accessing external storage. Just as "Background location tracking" is always suggested when it comes to keeping an app active in the background. We can consider them two "reference projects".

But that example is specific to the text MIME type and yes, you can easily change it (as indeed I did for audio files); it is a "Save As" but it is not suitable for every MIME type in reading, as in this case, audio files.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
i don't have a "file manager" (whatever that is). please delete my solution. thanks.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
If you want (almost) permanent access to a folder then you need to use ExternalStorage.
What "I" (another Italian member) needs would be to be able to make the user of his app choose audio files from his device without knowing the path and to be able to associate that audio file to a button, so as to be able to play the file in MediaPlayer when pressing the button, even in different "sessions".

So I guess the only solution is that the first time the file is selected, you should save it in the DirInternal.
I'll see if I can do it (and if the Italian member will be "happy" with it ?).

Thank you
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…