如何显示闹钟、通知、语音呼叫的当前铃声标题
我使用这段代码,我在这里或多或少找到了这段代码,但它总是返回相同的答案: “默认铃声是 Gleam”,但事实并非如此。
我想向用户展示设置的声音: 闹钟、系统通知、语音通话、日历通知、短信通知(我忘记了一些吗?)
我尝试使用此代码:
SharedPreferences prefsRingtones = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
Uri ringtoneUri = Uri.parse(prefsRingtones.getString("RingtonePref","DEFAULT_RINGTONE_URI"));
Ringtone ringtone = RingtoneManager.getRingtone(this, ringtoneUri);
String ringToneName = ringtone.getTitle(this);
或者使用 DEFAULT_RINGTONE_URI 使用 DEFAULT_ALARM_ALERT_URI、DEFAULT_NOTIFICATION_URI
I use this code, which I find more or less over here, but this return always same answer:
"Default ringtone is Gleam", which is not.
I would like to show users what sounds are set for:
alarm, system notification, voicecall, calendar notification, sms notification (did I forgot some?)
I tried to use this code:
SharedPreferences prefsRingtones = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
Uri ringtoneUri = Uri.parse(prefsRingtones.getString("RingtonePref","DEFAULT_RINGTONE_URI"));
Ringtone ringtone = RingtoneManager.getRingtone(this, ringtoneUri);
String ringToneName = ringtone.getTitle(this);
Or intead DEFAULT_RINGTONE_URI use DEFAULT_ALARM_ALERT_URI, DEFAULT_NOTIFICATION_URI
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
谢谢,它正在工作。对于所有其他,这是工作代码:
thank you, it is working. For all other this is working code:
尝试将 prefsRingtones 的默认值设置为 RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) 而不是“DEFAULT_RINGTONE”。
将 TYPE_NOTIFICATION 更改为您需要的声音类型。
Try setting the default value of prefsRingtones to RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) instead of "DEFAULT_RINGTONE".
Change TYPE_NOTIFICATION to which ever sound type you need.