android 8.0 的通知振动问题
Notification vibrate issue for android 8.0
我创建通知渠道以在 android 8.0 中显示通知,如下所示
NotificationChannel uploadChannel = new NotificationChannel(Constants.NOTIFICATION_CHANNEL_UPLOAD_ID,"Uploads", NotificationManager.IMPORTANCE_LOW);
uploadChannel.enableLights(false);
uploadChannel.setDescription("Uploads Channel");
notificationManager.createNotificationChannel(uploadChannel);
每次我显示通知时 phone 都会振动很多次。
我禁用通知频道的振动,如下所示
uploadChannel.enableVibration(false);
我创建通知如下
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, Constants.NOTIFICATION_CHANNEL_UPLOAD_ID);
但它不起作用 phone 每次通知时都会振动。
这是 Android 8 通知系统上的错误。我修改了 enableVibration
和 setVibrationPattern(null)
的不同组合,但它不起作用。
唯一能为我停止振动的解决方案是:
mNotificationChannel.setVibrationPattern(new long[]{ 0 });
mNotificationChannel.enableVibration(true);
仅供参考,即使我将振动模式设置为 0,但将 enableVibration
设置为 false
,它也会振动。
除了对我有用的 之外,我想补充一点,您可能需要删除该应用程序并重新安装,然后才能进行振动更改。如果应用程序被终止,频道将保留其初始设置并保持活动状态 - 因此如果您只是构建并 运行.
,则可能不会应用更改
我最初使用的是 NotificationManager.IMPORTANCE_DEFAULT
,无法让振动停止。使用 NotificationManager.IMPORTANCE_LOW
解决了这个问题。 NotificationManager.IMPORTANCE_MIN
也可以;看这里:https://developer.android.com/training/notify-user/channels#importance
添加notificationChannel.setVibrationPattern(new long[]{ 0L });
卸载应用程序或清除应用程序数据。 运行 再来一次 会成功的!
原因:channel_id已经报名申请
这个功能对我有用。我用它创建了完全禁用灯光、振动和声音的通知通道。
private void createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel serviceChannel = new NotificationChannel(
CHANNEL_ID,
"Foreground Service Channel",
NotificationManager.IMPORTANCE_DEFAULT
);
serviceChannel.setVibrationPattern(new long[]{ 0 });
serviceChannel.enableVibration(true);
serviceChannel.enableLights(false);
serviceChannel.setSound(null, null);
NotificationManager manager = getSystemService(NotificationManager.class);
manager.createNotificationChannel(serviceChannel);
}
}
我创建通知渠道以在 android 8.0 中显示通知,如下所示
NotificationChannel uploadChannel = new NotificationChannel(Constants.NOTIFICATION_CHANNEL_UPLOAD_ID,"Uploads", NotificationManager.IMPORTANCE_LOW);
uploadChannel.enableLights(false);
uploadChannel.setDescription("Uploads Channel");
notificationManager.createNotificationChannel(uploadChannel);
每次我显示通知时 phone 都会振动很多次。 我禁用通知频道的振动,如下所示
uploadChannel.enableVibration(false);
我创建通知如下
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, Constants.NOTIFICATION_CHANNEL_UPLOAD_ID);
但它不起作用 phone 每次通知时都会振动。
这是 Android 8 通知系统上的错误。我修改了 enableVibration
和 setVibrationPattern(null)
的不同组合,但它不起作用。
唯一能为我停止振动的解决方案是:
mNotificationChannel.setVibrationPattern(new long[]{ 0 });
mNotificationChannel.enableVibration(true);
仅供参考,即使我将振动模式设置为 0,但将 enableVibration
设置为 false
,它也会振动。
除了对我有用的
我最初使用的是 NotificationManager.IMPORTANCE_DEFAULT
,无法让振动停止。使用 NotificationManager.IMPORTANCE_LOW
解决了这个问题。 NotificationManager.IMPORTANCE_MIN
也可以;看这里:https://developer.android.com/training/notify-user/channels#importance
添加notificationChannel.setVibrationPattern(new long[]{ 0L });
卸载应用程序或清除应用程序数据。 运行 再来一次 会成功的!
原因:channel_id已经报名申请
这个功能对我有用。我用它创建了完全禁用灯光、振动和声音的通知通道。
private void createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel serviceChannel = new NotificationChannel(
CHANNEL_ID,
"Foreground Service Channel",
NotificationManager.IMPORTANCE_DEFAULT
);
serviceChannel.setVibrationPattern(new long[]{ 0 });
serviceChannel.enableVibration(true);
serviceChannel.enableLights(false);
serviceChannel.setSound(null, null);
NotificationManager manager = getSystemService(NotificationManager.class);
manager.createNotificationChannel(serviceChannel);
}
}