gpt4 book ai didi

android - 当手机锁定/应用程序未打开时,推送通知的振动不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 13:10:50 25 4
gpt4 key购买 nike

应用程序的推送通知总是被发送,这不是问题。问题是,只有在应用程序打开且手机未锁定的情况下,如果手机收到来自应用程序的新通知,手机才会振动。 如果应用未打开或手机已锁定,手机将不会在收到通知时振动。是否有办法让手机在收到通知时振动 即使它已锁定或应用程序未打开?可能是什么问题?根据我的发现,通知是在以下代码的帮助下创建的:

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"
}

如果不是静音模式,它会运行声音,当它是振动模式时会振动

关于android - 当手机锁定/应用程序未打开时,推送通知的振动不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45588629/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com