安卓关闭默认通知声音并振动



我想以优先级高发布我的通知,不需要声音或振动。 我什至不调用setSound((或setVibrate((,但是, 我将始终获得默认声音并随着我的通知而振动。有什么建议吗?

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())

请使用 NotificationManagerCompat.from(this(.cancelAll(( 清除横幅上的所有通知。 和 请去 禁用Android O上的通知声音 为了禁用通知声音。

最新更新