androidnotificationsandroid-8.0-oreonotification-channel

Android Notification vibrates with NotifiationChannel.enableVibration(false)


With API 26 (Android 8.0) we need to define a NotificationChannel for each Notification. Each channel has its own settings of disruptions (e.g. vibration, light, sound).

Problem: When I disable vibration for this channel and deploy this on a Android 8.0 (security update September 2017) phone (Nexus 5X), the notification triggers vibration anyway and is opened automatically (pop-in) which I did not set and want to disable.

  1. I register a NotificationChannel in my MainActivity:

    // Register NotificationChannels needed for API 26+ to display notification messages
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel runningChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID_RUNNING,
                getString(R.string.notification_channel_name_running), NotificationManager.IMPORTANCE_LOW);
        runningChannel.enableLights(false);
        runningChannel.enableVibration(false);
        mNotificationManager.createNotificationChannel(runningChannel);
    }
    
  2. I set the NotificationChannel for the Notification:

    notification = new NotificationCompat.Builder(context)
                .setContentIntent(onClickPendingIntent)
                .setChannelId(NOTIFICATION_CHANNEL_ID_RUNNING)
                .setOngoing(true)
                .setWhen(System.currentTimeMillis())
                .setAutoCancel(false)
                .build();
    

Update (security update 5th October 2017)

Now everything works as expected without workaround so I can choose targetSDK 26 (before, I used 25 to avoid this false behavior). For the case when other releases have a similar bug of other phones did not yet receive the newest update, I marked the workaround below as accepted answer.


Solution

  • This seems to work:

    runningchannel.setVibrationPattern(new long[]{0, 0, 0, 0,0, 0, 0, 0, 0});
    

    Yes, it's weird