我使用一个简单的选择器对话框让用户选择通知声音,下面是启动选择器的代码:
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/