【发布时间】:2020-07-13 05:47:33
【问题描述】:
在 Android 10 上,当我收到推送通知时,振动仅在应用打开时有效。如果它在后台或关闭,振动不起作用(但通知通过并且声音有效)。这是一个错误吗?但是在 Google 的错误跟踪器中找不到它。
我从我们的服务器发送带有数据负载的推送通知,这确保即使应用程序在后台,onMessageReceived() 也会被调用。确实如此,我可以调试它。
以下是通知通道的创建方式:
NotificationChannel mChannelUp = new NotificationChannel(CHANNEL_ID_ALERTS_UP, getApplicationContext().getString(R.string.alerts_up), NotificationManager.IMPORTANCE_HIGH);
mChannelUp.enableLights(true);
mChannelUp.enableVibration(true);
// mChannelUp.setVibrationPattern(new long[]{500, 250, 500, 250}); // doesn't help
mChannelUp.setLightColor(Color.BLUE);
AudioAttributes audioAttributesUp = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_NOTIFICATION_EVENT)
.build();
mChannelUp.setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + getPackageName() + "/" + R.raw.notif_sound_up), audioAttributesUp);
notificationManager.createNotificationChannel(mChannelUp);
还有通知本身:
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this, CHANNEL_ID_ALERTS_UP)
.setAutoCancel(true)
.setSmallIcon(R.drawable.ic_notif)
.setColor(ContextCompat.getColor(this, R.color.colorPrimary))
.setLargeIcon(logo)
.setVibrate(new long[]{250, 500, 250, 500})
.setLights(Color.parseColor("#039be5"), 500, 500)
.setContentTitle("some title")
.setContentText("some content")
.setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + getPackageName() + "/" + R.raw.notif_sound_up));
mBuilder.setContentIntent(resultPendingIntent);
Notification notif = mBuilder.build();
NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotifyMgr.notify(notificationId, notif);
【问题讨论】:
-
你尝试过哪些设备?
-
我能够在三星 Galaxy Note 10 和华为 P30 上重现这一点。
-
手机设置
Apps> 你的应用 >Battery Life>Background Activity为应用启用了吗? -
是的,它已启用:prntscr.com/twxkic 和 prntscr.com/twxky2
-
你是否在通知对象中发送了振动参数???在 HandleIntent 上尝试您的通知生成器 || (IntentHandler)
标签: android push-notification firebase-cloud-messaging android-notifications