我无法从RingtonePreference
获得声音标题。我搜索但找不到对我有用的解决方案。我做了什么 - 我设置RingtonePreference
进行设置,我想将声音标题设置为摘要。
XML
<RingtonePreference
android:key="@string/sound_key"
android:title="Sound"
android:ringtoneType="notification"
/>
活动
private RingtonePreference soundPreference = (RingtonePreference)findPreference(getResources().getString(R.string.sound_key));
soundPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
SharedPreferences.Editor editor = getSharedPreferences(MY_SOUND_PREF, MODE_PRIVATE).edit();
Log.i("here","soundPreference" );
Uri defaultRingtoneUri = RingtoneManager.getActualDefaultRingtoneUri(SettingA.this.getApplicationContext(), RingtoneManager.TYPE_NOTIFICATION);
Ringtone defaultRingtone = RingtoneManager.getRingtone(SettingA.this, defaultRingtoneUri);
String ringToneName = defaultRingtone.getTitle(SettingA.this);
editor.putString("ringtone", ringToneName);
editor.apply();
Log.i("ringToneName", ringToneName);
soundPreference.setSummary(ringToneName);
return true;
}
});
我尝试了其他类似的问题解决方案,但无法使其正常运行。有什么想法吗?