2

使用API​​ 26(Android 8.0),我們需要爲每個通知定義一個NotificationChannel。每個通道都有自己的中斷設置(例如振動,光線,聲音)。Android通知使用NotifiationChannel.enableVibration振動(false)

問題: 當停用振動此通道和上一個的Android 8.0(安全更新2017九月)電話(的Nexus 5X)部署此,通知觸發振動反正和自動打開(彈出式),我沒有設置並想禁用。

  1. 我在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); 
    } 
    
  2. 我設置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來避免這種錯誤行爲)。對於其他版本類似的其他手機缺陷尚未收到最新更新的情況,我將下面的解決方法標記爲已接受的答案。

+0

試着改變重要性級別NotificationManager.IMPORTANCE_HIGH –

+0

感謝您的建議@ArnavM。但是,它不會改變行爲(仍會振動並彈出通知)。你能解釋爲什麼你認爲這應該有所作爲? – hb0

回答

1

這似乎工作:?

runningchannel.setVibrationPattern(new long[]{0, 0, 0, 0,0, 0, 0, 0, 0}); 

是的,它的怪異

+0

謝謝@Piotr,我會盡快檢查出來,並在工作時將您的答案標記爲正確。乾杯! – hb0

+0

我的Nexus 5X系統更新「2017年10月5日」。在此更新之後,我沒有看到問題中提到的錯誤行爲。因此,我不需要使用您的解決方法,但它似乎是合法的,因此我將其標記爲正確的其他人可能尚未收到最新的Android 8更新,或在未來版本中獲得此錯誤行爲。謝了哥們! – hb0

+0

沒有爲我工作 –