使用API 26(Android 8.0),我們需要爲每個通知定義一個NotificationChannel。每個通道都有自己的中斷設置(例如振動,光線,聲音)。Android通知使用NotifiationChannel.enableVibration振動(false)
問題: 當停用振動此通道和上一個的Android 8.0(安全更新2017九月)電話(的Nexus 5X)部署此,通知觸發振動反正和自動打開(彈出式),我沒有設置並想禁用。
我在MainActivity註冊NotificationChannel:
// Register NotificationChannels needed for API 26+ to display notification messages if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel runningChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID_RUNNING, getString(R.string.notification_channel_name_running), NotificationManager.IMPORTANCE_LOW); runningChannel.enableLights(false); runningChannel.enableVibration(false); mNotificationManager.createNotificationChannel(runningChannel); }
我設置NotificationChannel的通知:
notification = new NotificationCompat.Builder(context) .setContentIntent(onClickPendingIntent) .setChannelId(NOTIFICATION_CHANNEL_ID_RUNNING) .setOngoing(true) .setWhen(System.currentTimeMillis()) .setAutoCancel(false) .build();
更新(安全更新5日2017年十月)
現在一切都按預期工作,沒有解決方法,所以我可以選擇targetSDK 26(以前,我用25來避免這種錯誤行爲)。對於其他版本類似的其他手機缺陷尚未收到最新更新的情況,我將下面的解決方法標記爲已接受的答案。
試着改變重要性級別NotificationManager.IMPORTANCE_HIGH –
感謝您的建議@ArnavM。但是,它不會改變行爲(仍會振動並彈出通知)。你能解釋爲什麼你認爲這應該有所作爲? – hb0