[英]How to read ringtone from ringtone preferences
i tried below code. 我尝试下面的代码。 But i'm not able to read the ring tone from ringtone preferences. 但是我无法从铃声偏好中读取铃声。
<RingtonePreference
android:title="@string/RING_TONE_SETTING"
android:summary="@string/RING_TONE_SETTING_DESCRIPTION"
android:ringtoneType="notification"
android:showSilent="true"
android:showDefault="true"
android:key="prefnotificationTone"/>
This is how i'm reading, 这就是我的阅读方式
SharedPreferences preference = PreferenceManager.getDefaultSharedPreferences(this);
String strRingtonePreference = preference.getString("prefnotificationTone", "DEFAULT_SOUND");
Uri notification = Uri.parse(strRingtonePreference);
mMPlayer = MediaPlayer.create(getApplicationContext(), notification);
mMPlayer.start();
I'm getting DEFAULT_SOUND always. 我总是得到DEFAULT_SOUND。
将以下属性添加到XML的首选项中:
android:persistent="true"
SharedPreferences preference = PreferenceManager.getDefaultSharedPreferences(context);
String strRingtonePreference = preference.getString("ring_tone_pref", "DEFAULT_SOUND");
You just got the uri of the ringtone above. 您刚刚收到了铃声的uri。 you have to parse it to url and then get the corresponding ringtone from system. 您必须将其解析为url,然后从系统获取相应的铃声。
defaultRingtoneUri = Uri.parse(strRingtonePreference);
defaultRingtone = RingtoneManager.getRingtone(this, defaultRingtoneUri);
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.