4 回答

TA貢獻1803條經驗 獲得超6個贊
推送消息有3種類型
通知
數據
和兩者
推送消息基本上是一個 json 負載:
payload:{
notificacion...
data
}
每種類型的推送消息的規則是不同的。在您的情況下,您正在使用 Firebase Web 控制臺并添加自定義數據,這意味著您的有效負載將包含通知和數據。
對于組合類型,背景中的行為是使用默認通知(NotificationCompat,視覺類型)并打開清單中注冊的默認活動。在活動中,您可以獲得數據。
假設您的默認活動稱為 MainActivity
public class MainActivity {
onCreate...{
//... usual stuff
Intent fcmIntent = getIntent();
if fcmIntent != null
//check the extras and forward them to the next activity if needed
}
}

TA貢獻1864條經驗 獲得超6個贊
您需要在 firebase 通知數據集中設置 click_action 才能從后臺接收數據并實現 onMessageReceived 來處理前臺數據

TA貢獻1831條經驗 獲得超4個贊
我解決了這個購買處理通知,handleIntent當應用程序被殺死時,在后臺和前臺。我完全忽略了該onMessageReceived(@NonNull RemoteMessage message)方法,因為當應用程序處于后臺時它似乎不起作用。
@Override
public void handleIntent(Intent intent) {
Log.d( "FCM", "handleIntent \n"+intent.getStringExtra("data"));
String messageTitle = intent.getStringExtra("title");
String messageBody = intent.getStringExtra("body");
//from here pass the values to a method to show your notification.
}
在您的活動中,您將能夠從意圖中檢索任何數據。
要重定向到您想要的活動,您必須將 click_action 添加到您的負載中。這是我的有效負載的樣子:
"notification": {
"body": "Your message is here",
"title": "Hey Robby",
"discount_code": "baba-blacksheep",
"uid": "2",
"click_action": "OPEN_ACTIVITY_FROM_NOTIFICATION"
}
添加回答
舉報