Android 8.0的通知振动问题

Man*_*ish 5 notifications android android-8.0-oreo

我创建通知通道,以在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);
Run Code Online (Sandbox Code Playgroud)

每当我显示通知手机振动很多次.我从通知通道禁用振动,如下所示

uploadChannel.enableVibration(false);
Run Code Online (Sandbox Code Playgroud)

我创建如下通知

 NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, Constants.NOTIFICATION_CHANNEL_UPLOAD_ID);
Run Code Online (Sandbox Code Playgroud)

但它不工作电话随着每个通知振动.

小智 18

这是Android 8通知系统上的一个错误.我修修补补用不同的组合enableVibrationsetVibrationPattern(null),但它不工作.

只有阻止振动的解决方案是:

mNotificationChannel.setVibrationPattern(new long[]{ 0 });
mNotificationChannel.enableVibration(true);
Run Code Online (Sandbox Code Playgroud)

仅供参考,即使我将振动模式设置enableVibration为0,但设置为振动模式false,它也会振动.

  • 如果它不起作用,请参阅[Roland van der Linden的答案](/sf/ask/3248175731/#51289889) (4认同)

Rol*_*den 17

除了Ahmadul Hoq的答案,这对我有用之外,我想补充一点,你可能需要删除应用程序并在振动发生变化之前重新安装它.如果应用程序被终止,通道会保持其初始设置并保持活动状态 - 因此,如果您只是构建并运行,则可能无法应用更改.

  • 或者,你可以**清除应用数据** (2认同)
  • 如果您要将对生产中的通知渠道所做的更改以及当前安装了您的应用程序的用户应用,请将您的渠道 ID 更改为新的。 (2认同)