应用程序的推送通知总是被发送,这不是问题。问题是,只有在应用程序打开且手机未锁定的情况下,如果手机收到来自应用程序的新通知,手机才会振动。 如果应用未打开或手机已锁定,手机将不会在收到通知时振动。是否有办法让手机在收到通知时振动 即使它已锁定或应用程序未打开?可能是什么问题?根据我的发现,通知是在以下代码的帮助下创建的:
public class NotifyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.notify(
remoteMessage.getMessageId(),
1,
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_paperplane)
.setContentTitle(remoteMessage.getNotification().getTitle())
.setContentText(remoteMessage.getNotification().getBody())
.setVibrate(new long[] { 150, 300, 150, 600})
.setAutoCancel(true)
.build());
super.onMessageReceived(remoteMessage);
}
}
list 具有振动和唤醒锁权限:
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" /
在通知负载中添加:
"notification":{
"sound":"default"
}
如果不是静音模式,它会运行声音,当它是振动模式时会振动
我是一名优秀的程序员,十分优秀!