Service.startForeground 振动设备

Add*_*dev 4 java android android-notifications kotlin

我正在为我的一项服务使用startForeground()调用:

NotificationCompat.Builder notifBuilder = 
                              new NotificationCompat.Builder(this, "my_channel")
                              .setContentTitle("Loading");
startForeground(1, notifBuilder.build());
Run Code Online (Sandbox Code Playgroud)

问题是,因为我使用我独特的通知频道并且它有振动:

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);
Run Code Online (Sandbox Code Playgroud)

startForeground()呼叫产生振动。

尝试了一些配置:

不工作:notifBuilder.setVibrate(new long[]{0,0})也不notifBuilder.setDefaults(~Notification.DEFAULT_VIBRATE)

在我的设备上工作notifBuilder.setVibrate(null)或使用未注册的频道 ID,但我不确定这是否会导致其他版本或设备崩溃。

如何在不声明新频道的情况下避免这种振动?

Jam*_*ken 5

要创建的NotificationChannelIMPORTANCE_DEFAULT该文件说:

默认通知重要性:随处可见,发出噪音,但不会在视觉上侵入。

你可能想要IMPORTANCE_LOW

低通知重要性:随处可见,但不具有侵入性。

如果你想"my_channel"留下来IMPORTANCE_DEFAULT,你可以为这个服务创建一个不同重要性的新频道。