I got the READ_MEDIA_AUDIO
permission, and let user select an audio file. Audio file was played fine. But I want to load the same audio file at next startup, without making the user select the same file again (which is obviously inconvenient for the user). I saved the uri.toString() in the preference, and in onCreate, I read the string, and created the uri again.
val sharedPreferences = getSharedPreferences("settings", Context.MODE_PRIVATE)
val audioUriString = sharedPreferences.getString("last-audio", null)
if (audioUriString!=null)
{
audioUri = Uri.parse(audioUriString)
mp.setDataSource(this, audioUri!!)
mp.prepareAsync()
}
However, this did not work. It caused:
java.io.FileNotFoundException: null: open failed: ENOENT (No such file or directory)
What I am trying to do is not possible, and the user must select the same file in each session?
minSdk = 31, targetSdk = 34