0

The below link does answer the question about alternatives.

Environment.getExternalStorageDirectory() deprecated in API level 29 java

It answers how to not use the external storage directory and use the internal app specific directories. And also how to access media files using the other available API's. Non media files can be accessed only via the System picker, which is the main concern here. I am using my app as a file manager and I will request for MANAGE_EXTERNAL_STORAGE and will follow the process which is totally fine for me.

But the issue is , I want to replace this deprecated function with its alternative. The function which gives me the external storage directory path which looks something like: storage/emulated/0/

But I get from the alternatives mentioned in android developers page and the above link is : storage/Android/users/data/0/com.mypackagename.myapp/

I can still use the deprecated function as it still works , but for filemanagers or antivirus apps(which have special access with MANAGE_EXTERNAL_STORAGE permission), what is alternative for Environment.getExternalStorageDirectory() , if Google says that it is deprecated. Without using this deprecated function , there is no way that any filemanagers can get the path of the external storage directory.

  • There is no alternative. Use it! – blackapps Sep 30 '21 at 20:24
  • https://developer.android.com/reference/android/os/storage/StorageVolume?hl=en#getDirectory() – CommonsWare Oct 01 '21 at 11:05
  • @CommonsWare I checked this solution as well. And it works for API 30 and above , because getDirectory() function was introduced only in API 30 right. I used https://stackoverflow.com/a/67349291/15400652 .But the code for API < 30 doesn't work. If I get the code for that, I should be good actually . Any idea how to do that? – Ruthwik R Oct 04 '21 at 05:53
  • "Any idea how to do that?" -- use `Environment.getExternalStorageDirectory()` on older devices. Use `StorageVolume` on newer devices. – CommonsWare Oct 04 '21 at 10:37
  • Okay, I guess I still need to continue using Environment.getExternalStorageDirectory() . Got my answer. Hope that Android does not move the function from deprecated to unavailable state until they give an alternative to API < 30. – Ruthwik R Oct 04 '21 at 15:59

0 Answers0