无法从RingtonePreference获取声音标题

时间:2018-06-07 15:51:02

标签: java android sharedpreferences android-preferences ringtone

我无法从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;
            }
        });

我尝试了其他类似的问题解决方案,但无法使其正常运行。有什么想法吗?

0 个答案:

没有答案