-1
我正在創建一個出租車應用程序。每當乘客請求乘坐時,請求將由服務器處理,並通知出租車司機。驅動程序應用程序包含一個具有警報的活動,在接收到FCM通知時將開始振鈴。當應用程序處於前臺時,FCM可以很好地工作,但當應用程序處於後臺或處於關閉狀態時,它不會啓動警報活動。即使應用程序處於後臺,是否有任何方法可以從通知中啓動預期的未決意圖。啓動應用程序處於後臺或完全關閉狀態時通知單上的活動
Intent intent = new Intent(this, AlarmActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.alert)
.setContentTitle("Firebase Push Notification")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());