Android关闭默认通知声音并振动

时间:2019-10-17 04:43:58

标签: android android-notifications

我要优先发布通知,不需要声音或振动。 我什至不叫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())

1 个答案:

答案 0 :(得分:0)

请使用NotificationManagerCompat.from(this).cancelAll()清除横幅上的所有通知。并请转到Disable notification sound on Android O以获得通知音。