I am new in programming and want to make a file manager in android studio. I am facing problems in listing all device folders in API level 29 after getExteralStorageDirectory
was deprecated.
Asked
Active
Viewed 1,917 times
3
-
Which problems exactly? – blackapps Apr 25 '20 at 06:20
-
in making a uri of for playing a mp3 file..showing uri is null – DikShU Apr 25 '20 at 10:38
-
So you do that all without any code? – blackapps Apr 25 '20 at 10:39
-
i have tried this code but everytime it is showing uri is null......... mediaplayer = MediaPlayer() var uri: Uri = Uri.parse((getAppExternalFilesDir().toString() + namecopied)) Toast.makeText(this, uri.toString(), Toast.LENGTH_SHORT).show() mediaplayer = MediaPlayer.create(this, uri) mediaplayer.prepare() mediaplayer.start() – DikShU Apr 25 '20 at 10:43
-
Please put your code in your post. – blackapps Apr 25 '20 at 12:08
-
Can you help me with listing all files from Download directory in android-Q? https://stackoverflow.com/questions/63593112/do-we-need-permission-to-get-all-files-that-is-self-created-by-the-app-after-the – jazzbpn Aug 27 '20 at 10:12
1 Answers
3
According to the documentation, you will have to use ACTION_OPEN_DOCUMENT_TREE. This will provide you with the URI
of selected directory
, once you have the URI
then you can access all the children of that directory
. From docs
Grant access to a directory's contents
File management and media-creation apps typically manage groups of files in a directory hierarchy. To provide this capability in your app, use the ACTION_OPEN_DOCUMENT_TREE intent action, which allows the user to grant access to an entire directory tree. Your app can then access any file in the selected directory and any of its sub-directories.
There is also ActionOpenDocumentTree sample app on github which shows how to implement this feature.
-
As I linked in the answer [ActionOpenDocumentTree](https://github.com/android/storage-samples/tree/228c8e0aa19586bfcf36318ddb191719537a45a4/ActionOpenDocumentTree) is an example project on github. You can clone the repo on your local machine to understand the code better. – mightyWOZ Apr 25 '20 at 10:44
-
Can you help me with listing all files from Download directory in android-Q? https://stackoverflow.com/questions/63593112/do-we-need-permission-to-get-all-files-that-is-self-created-by-the-app-after-the – jazzbpn Aug 27 '20 at 10:12