Having received the name of the ringtone for "Hangouts Message", do I get 11?

I am trying to get the name of the alarm that the user just selected. It works for ALL of the anxieties I tested. So far, there is only one exception: Hangout Message. I select the alarm as follows:

Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select ringtone for notifications:"); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); if (alarm.getSound() != null) { intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, alarm.getSound()); } else { Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, alert); } intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,RingtoneManager.TYPE_ALARM); startActivityForResult(intent, alarm.getID()); 

and my onActivityResponse :

 protected void onActivityResult(int id, int resultCode, Intent data) { if (resultCode == RESULT_OK) { Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); if (id != -1) { for (int i = 0; i < Alarms.size(); i++) { Alarm alarm = Alarms.get(i); if (alarm.getID() == id) { alarm.setSound(ringtone); alarm.UpdateView(); DB.SaveAlarm(alarm); break; } } } } } 

I have a pretty simple way to get ringtone names from a URI:

 Ringtone tone = RingtoneManager.getRingtone(this.Con, this.Sound); AlarmSound.setText(tone.getTitle(this.Con).toUpperCase()); 

this.Con is a context, usually an Activity , potentially a Service . The Alarm class is my own class. this.Sound is the URI for the ringtone. For any other alarm that is not a Hangout message, this works fine and gives me the correct name for the ringtone. For a Hangouts message, I get 11 and no errors. URI content://media/external/audio/media/11 , so I see where it got 11 , but I want to translate it into my name. I do not want to hard code a special case for him.

How can I get a Hangout message from this URI?

I want to note that in my code, where I set the existing URI, if the Hangout Message is an existing sound, it will pre-select it correctly, like any other ringtone. The ringtone selector correctly displays its name, and the application really plays the sound correctly when the time comes.

EDIT: I found where the Android DeskClock app for stocks gets the name of the name here (line 1356) :

 private String getRingToneTitle(Uri uri) { // Try the cache first String title = mRingtoneTitleCache.getString(uri.toString()); if (title == null) { // This is slow because a media player is created during Ringtone object creation. Ringtone ringTone = RingtoneManager.getRingtone(mContext, uri); title = ringTone.getTitle(mContext); if (title != null) { mRingtoneTitleCache.putString(uri.toString(), title); } } return title; } 

Besides caching, he does nothing else but me. It makes me think that maybe I am creating a problem elsewhere, but I donโ€™t know what else could affect this. Can rooting or the Xposed framework have this specific side?

+1
source share
1 answer

If I really read magazines, I could think about it a long time ago.

Since this is a tune provided by another application, I need a new permission to get information about this. I needed READ_EXTERNAL_STORAGE , and after adding it, it worked perfectly.

+2
source

Source: https://habr.com/ru/post/1213635/


All Articles