Disable vibration for a notification

前端 未结 7 1153
北荒
北荒 2020-12-09 15:11

I\'m writing an app using notification. Google developer guidelines encourages developers to provide settings to customize the notifications (disable vibration, set notifica

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-09 16:05

    private void removeSoundAndVibration(Notification notification) {
            notification.sound = null;
            notification.vibrate = null;
            notification.defaults &= ~DEFAULT_SOUND;
            notification.defaults &= ~DEFAULT_VIBRATE;
    

    This code is from Notification Compat Api Class. This should work, add all these to your builder.

提交回复
热议问题