3

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.

hb0
  • 3,350
  • 3
  • 30
  • 48
  • try changing importance level?NotificationManager.IMPORTANCE_HIGH – Arnav M. Sep 28 '17 at 10:11
  • Thanks for your suggestion @ArnavM. However, it does not change the behaviour (still vibrates and pops up the notification). Can you explain why you think that this should have made any difference? – hb0 Sep 28 '17 at 10:24
  • a related point to take care off not to make an incorrect implementation by using both enableVibration() and setVibrationPattern() take look here: https://proandroiddev.com/oreo-notification-feature-a-critical-issue-that-could-restart-your-android-phone-ca122fa4d9cb – Ali Asadi Nov 03 '18 at 00:14

1 Answers1

3

This seems to work:

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

Yes, it's weird

Piotr
  • 238
  • 2
  • 12
  • Thanks @Piotr, I will check it out as soon as there is time and mark your answer as correct when it works. Cheers! – hb0 Oct 09 '17 at 16:09
  • My Nexus 5X got a system update "October 5th, 2017". After this update I do not get the false behavior mentioned in the question. Thus, I did not need to use your workaround but it seems legit so I mark it as the correct aswer others might not yet receive the newest Android 8 update or get this false behavior in future releases. Thanks, mate! – hb0 Oct 11 '17 at 09:00
  • 2
    This worked for me. When modifying notification channels, always uninstall and install the app. – krisDrOid Nov 01 '18 at 06:51
  • @hb0 I want to mention that there is an issue if you make an incorrect implementation take a look at this post https://proandroiddev.com/oreo-notification-feature-a-critical-issue-that-could-restart-your-android-phone-ca122fa4d9cb – Ali Asadi Nov 03 '18 at 00:06
  • Thanks for your answer, uninstalling and installing the app worked for me. – Kevin Ramirez Zavalza Feb 29 '20 at 18:37
  • @krisDrOid thanks I was wondering why there are no changes when I set the vibration until I found your comment and reinstalled the app. Absolute saviour – Kristian Oct 05 '22 at 21:58