伙計們,我正在使用 FCM 向我的 android 應用程式發送通知,它運行良好,但是當我單擊通知時,它會將我發送到我在此處設定的特定活動:
@Override
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
Intent intent = new Intent(this, activity_togo_to.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "101")
.setSmallIcon(R.drawable.ic_add)
.setContentTitle(remoteMessage.getNotification().getTitle())
.setContentText(remoteMessage.getNotification().getBody())
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
// Set the intent that will fire when the user taps the notification
.setContentIntent(pendingIntent)
.setAutoCancel(true);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
// notificationId is a unique int for each notification that you must define
notificationManager.notify(1, builder.build());
}
我的問題我不想在單擊通知時轉到相同的活動。
所以我的通知系統是這樣作業的:
我在 MySQL 資料庫 A 和 B 中有兩個表:
當一行被添加到表 A --> 帶有標題的推送通知:“有一個新專案 A”
當一行被添加到表 B --> 帶有標題的推送通知:“有一個新專案 B”
當我點擊通知時:
標題為:“有一個新專案 A” --> 轉到活動 A
標題:“有一個新專案 B” --> 轉到活動 B
我怎樣才能實作這些家伙,我真的需要它。
感謝任何幫助。如果不可能,請告訴我。
uj5u.com熱心網友回復:
您的通知的未決意圖必須是活動 A 或 B。您可以將引數從遠程服務器傳遞給您的通知到 remoteMessage.getData()。
例如:
with(remoteMessage.data) {
// Extract data
type = get(PARAM_TYPE)
variation = get(PARAM_VARIATION)
priority = getNotificationPriorityFromString(get(PARAM_PRIORITY))
title = get(PARAM_TITLE)
message = get(PARAM_MESSAGE)
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/385224.html
標籤:爪哇 安卓 火力基地 firebase-cloud-消息
上一篇:將物件添加到陣列而不覆寫
