使用API 26(Android 8.0)时,我们需要为每个通知定义一个NotificationChannel。每个频道都有自己的中断设置(例如振动、灯光、声音)。
问题: 当我在此频道上禁用振动并在Android 8.0(安全更新2017年9月)手机上部署时(Nexus 5X),通知仍会触发振动并自动打开(弹出),而这不是我设置和想要禁用的。
问题: 当我在此频道上禁用振动并在Android 8.0(安全更新2017年9月)手机上部署时(Nexus 5X),通知仍会触发振动并自动打开(弹出),而这不是我设置和想要禁用的。
I register a NotificationChannel in my MainActivity:
// 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); }
I set the NotificationChannel for the Notification:
notification = new NotificationCompat.Builder(context) .setContentIntent(onClickPendingIntent) .setChannelId(NOTIFICATION_CHANNEL_ID_RUNNING) .setOngoing(true) .setWhen(System.currentTimeMillis()) .setAutoCancel(false) .build();
更新(安全更新 2017年10月5日)
现在所有事情都按照预期工作,无需任何解决方法,因此我可以选择目标SDK 26(之前,我使用25来避免这种错误行为)。对于其他版本存在类似错误或其他手机尚未收到最新更新的情况,我将下面的解决方法标记为接受的答案。