gpt4 book ai didi

android - RingtoneManager 显示电话铃声而不是通知声音

转载 作者:行者123 更新时间:2023-11-30 02:06:04 26 4
gpt4 key购买 nike

我使用一个简单的选择器对话框让用户选择通知声音,下面是启动选择器的代码:

 Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION | RingtoneManager.TYPE_ALARM);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, getString(R.string.selectSound));
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(LocalCfg.getNotificationSound()));
startActivityForResult(intent, SELECT_RINGTONE_REQUEST);

LocalCfg.getNotificationSound() 只是检查 SharedPreferences 中的设置并返回默认通知声音 Uri,以防设置尚未完成存在:

    public static String getNotificationSound() {
return mPrefs.getString(KEY_PREF_NOTIFY_SOUND_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION).toString());
}

在所有测试的手机上观察到的问题:列出的“默认”声音不是通知/警报声音,而是实际的手机铃声(系统默认或用户设置的自定义)。

一些手机(Samsung Galaxy Young、Xperia Z1 Compact)将其显示为“默认通知声音”(实际上是错误的),其他一些(Nexus 设备、SDK 22)将其显示为“默认铃声”。

如果我显式传递 RingtoneManager.TYPE_NOTIFICATION | 为什么会发生这种情况? RingtoneManager.TYPE_ALARM 标志?

最佳答案

额外使用 RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI:

Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION | RingtoneManager.TYPE_ALARM);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, getString(R.string.selectSound));
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(LocalCfg.getNotificationSound()));
startActivityForResult(intent, SELECT_RINGTONE_REQUEST);

关于android - RingtoneManager 显示电话铃声而不是通知声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30638492/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com