I thought currently, all apps Google Play store, suppose not able to create directory/ files in Environment.getExternalStorageDirectory / Environment.getExternalStoragePublicDirectory?
Since Android 11, We are encouraged to only use
Context.getExternalFilesDir(null)
In my Android 11 device
Context.getExternalFilesDir(null) will return
/storage/emulated/0/Android/data/com.xxx.yyy/files/
Environment.getExternalStorageDirectory() will return
/storage/emulated/0
Environment.getExternalStoragePublicDirectory("Music") will return
/storage/emulated/0/Music
I notice majority sound recording apps in the market, still able to write to storage/emulated/0, after gaining WRITE_EXTERNAL_STORAGE runtime permission.
For instance
https://play.google.com/store/apps/details?id=com.andrwq.recorder able write to /storage/emulated/0/SmartMob/SmartRecorder directory - https://i.imgur.com/mBkHLkL.png
https://play.google.com/store/apps/details?id=myrecorder.voicerecorder.voicememos.audiorecorder.recordingapp able write to /storage/emulated/0/Music/MyRecorder - https://i.imgur.com/a8YFGus.png
I have written a quick code snippet to try. I have confirmed by using a norm way, it seems like it is not able to create directory/ file using path returned by Environment.
// Prior running the following code, I have grant WRITE_EXTERNAL_STORAGE runtime permission.
// "/storage/emulated/0/Music/Cheok"
File file = new File(Environment.getExternalStoragePublicDirectory("Music"), "Cheok/");
// All returns false!!
Log.i("CHEOK", file + " exists " + file.exists());
Log.i("CHEOK", file + " mkdirs " + file.mkdirs());
Log.i("CHEOK", file + " exists " + file.exists());
Do you have any idea, what technique these apps are using, which makes them able to write to location like /storage/emulated/0/SmartMob/SmartRecorder, /storage/emulated/0/Music/MyRecorder, ... ?
By doing so, this gives a huge advantage, where the app data is retained, after the app is uninstalled.