关于 Android O+ 上的通知声音。 有些手机的“通知设置”窗口没有显示声音选择按钮(甚至没有振动按钮)。 这里有几个例子:
- 三星A5
- 华为荣耀View 10
(不是小品牌……我会说)
他们在 Android 8 上使用 Gmail 应用程序(菜单 -> 设置 -> 帐户 -> 通知设置)进行了测试。
在这里Android O - Notification Channels - Change Vibration Pattern or Sound Type是避免“标准”窗口的解决方案,但我们为什么要重新发明轮子?
我还缺少其他选项吗?
谢谢,
最大
附言 这是荣耀 9/Android 8.0.0 的屏幕截图。 channel 名称是“Mail”(意大利语中的“Posta”)。对于声音(意大利语中的“Suoneria”),只有一个开/关开关。
最佳答案
这是一团糟。您需要为不同的品牌/设备添加解决方法。这是我们用来处理它的流程:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !isDeviceWithWorkaround()) {
// Send to notification channel settings (See https://developer.android.com/training/notify-user/channels#UpdateChannel)
}else{
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Sound");
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(someExistingRingTone));
if (isDeviceWithWorkaround()) {
intent.setPackage("com.android.providers.media");
}
try {
startActivityForResult(intent, reqCode);
} catch (ActivityNotFoundException e) {
if (isDeviceWithWorkaround()) {
Log.i(TAG, "Failed to find preferred package [" + intent.getPackage() + "]. Trying again without package.");
intent.setPackage(null);
startActivity(intent);
}
}
}
现在的情况是,如果它是您所说的存在已知问题的设备,我们会将它们发送到良好的旧铃声选择器。
我相信 com.android.providers.media
包在普通 Android 上没有启动 Activity ,但在华为上它会打开媒体商店,我们可以从中获取铃声 URI可以用作通知声音。 (我们不希望用户最终使用其他可能无法使用的铃声选择器。我们一直建议我们的用户使用 https://play.google.com/store/apps/details?id=com.angryredplanet.android.rings_extended,但它不适用于 Android 8 上的华为)。
关于安卓 O+ : Some phones seem to lack the option to change sound type for notifications,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51983074/