我正在使用startForeground()方法来启动我的一个服务:
NotificationCompat.Builder notifBuilder =
new NotificationCompat.Builder(this, "my_channel")
.setContentTitle("Loading");
startForeground(1, notifBuilder.build());
问题在于,由于我正在使用我的独特通道进行通知并且它具有振动功能:
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel mChannel =
new NotificationChannel("my_channel", "Notifications", NotificationManager.IMPORTANCE_DEFAUL);
mChannel.enableLights(true);
mChannel.enableVibration(true);
notificationManager.createNotificationChannel(mChannel);
startForeground()
调用会触发震动。
尝试了一些配置:
无效:notifBuilder.setVibrate(new long[]{0,0})
或 notifBuilder.setDefaults(~Notification.DEFAULT_VIBRATE)
在我的设备上有效的是 notifBuilder.setVibrate(null)
或使用未注册的通道 ID,但我不确定这是否会导致其他版本或设备崩溃。
如何避免声明新通道而不触发震动?