如何显示闹钟、通知、语音呼叫的当前铃声标题

发布于 2024-12-08 12:35:17 字数 561 浏览 0 评论 0原文

我使用这段代码,我在这里或多或少找到了这段代码,但它总是返回相同的答案: “默认铃声是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

骄兵必败 2024-12-15 12:35:17

谢谢,它正在工作。对于所有其他,这是工作代码:

Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone ringtone = RingtoneManager.getRingtone(this, ringtoneUri);
String ringToneName = ringtone.getTitle(this);

thank you, it is working. For all other this is working code:

Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone ringtone = RingtoneManager.getRingtone(this, ringtoneUri);
String ringToneName = ringtone.getTitle(this);
ぶ宁プ宁ぶ 2024-12-15 12:35:17

尝试将 prefsRingtones 的默认值设置为 RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) 而不是“DEFAULT_RINGTONE”。

SharedPreferences prefsRingtones =  PreferenceManager.getDefaultSharedPreferences(getBaseContext());
Uri ringtoneUri = Uri.parse(prefsRingtones.getString("RingtonePref",RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)));
Ringtone ringtone = RingtoneManager.getRingtone(this, ringtoneUri);
String ringToneName = ringtone.getTitle(this);

将 TYPE_NOTIFICATION 更改为您需要的声音类型。

Try setting the default value of prefsRingtones to RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) instead of "DEFAULT_RINGTONE".

SharedPreferences prefsRingtones =  PreferenceManager.getDefaultSharedPreferences(getBaseContext());
Uri ringtoneUri = Uri.parse(prefsRingtones.getString("RingtonePref",RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)));
Ringtone ringtone = RingtoneManager.getRingtone(this, ringtoneUri);
String ringToneName = ringtone.getTitle(this);

Change TYPE_NOTIFICATION to which ever sound type you need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文