简体   繁体   中英

Android turn off default notification sound and vibrate

I want to post my notification with priority hight and no sound or vibration is needed. I don't even call setSound() or setVibrate(), however, I will always get the default sound and vibrate with my notification. Any advice?

notificationBuilder = NotificationCompat.Builder(context, NotificationKeys.CHANNEL_NEW_ORDER_ID)
            .setContentIntent(pendingIntent)
            .setContentTitle(context.getString(R.string.app_name))
            .setCustomContentView(collapseView)
            .setStyle(NotificationCompat.DecoratedCustomViewStyle())
            .setSmallIcon(R.drawable.ic_app_logo_primary)
            .setFullScreenIntent(pendingIntent, true)
            .setOnlyAlertOnce(true)
            .setOngoing(true)
            .setAutoCancel(true)
            // I also tried with null but didn't work
            .setSound(null)
            .setVibrate(null)

NotificationManagerCompat.from(context).notify(myNotificationKey, notificationBuilder.build())

Please Use NotificationManagerCompat.from(this).cancelAll() for clear all notification on banner. and Please go Disable notification sound on Android O for desable the sound of notification.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM