Answer the question
In order to leave comments, you need to log in
How to access a file by URI in Android 11?
The user selects any ringtone from the device, this ringtone is played when some event occurs.
Before android 11, the following code worked perfectly:
fun onSomeEvent() {
val uri = preferences.ringtoneUri
val ringtone = RingtoneManager.getRingtone(appContext, uri)
ringtone.play()
}
fun onChangeRingtoneClick() {
val intent = Intent(RingtoneManager.ACTION_RINGTONE_PICKER)
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION)
startActivityForResult(intent, REQUEST_CODE)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (resultCode == RESULT_OK && requestCode == REQUEST_CODE) {
preferences.ringtoneUri = data?.extras?.get(EXTRA_RINGTONE_PICKED_URI)
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question