Conditionally vibrate in Android notification channel

18 Views Asked by At

I made an app that vibrates periodically. But I want the device to vibrate only if the variable YYYY is true. My problem is then how to enable/disable the vibration.

I created the channel with

NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_DEFAULT);
chan.setVibrationPattern(new long[]{0,200,200,200});
chan.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);

I cannot do

chan.enableVibration(YYYY);

or

chan.setVibrationPattern((YYYY) ? <pattern> : null);

since both are Only modifiable before the channel is submitted to NotificationManager.createNotificationChannel(NotificationChannel).

Is there any way of doing this without recreating the whole notification each time?

0

There are 0 best solutions below