應用程序的推送通知始終發送,但這不是問題。問題是,只有當應用程序打開且手機未鎖定時,手機纔會收到來自應用程序的新通知。 如果應用程序未打開或手機已鎖定,手機將不會收到通知時震動。 是否有辦法使手機在收到通知時發生振動即使它被鎖定或應用程序未打開?可能是什麼問題?從我發現,通知與下面的代碼的幫助下創建:當手機鎖定/應用程序未打開時,推送通知中的振動無法工作
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);
}
}
清單有震動和WAKE_LOCK權限:
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE"/
完美工作,感謝您的幫助。有沒有辦法使聲音和振動? – Cctest