從火力地堡資料爲準:
在背景執行的應用程序 手柄通知消息當你的應用程序是在後臺,Android的指示通知消息到系統托盤。用戶點擊通知會默認打開應用程序啓動器。這包括包含通知和數據負載(以及通知控制檯發送的所有消息)的消息。在這些情況下,通知將傳遞到設備的系統托盤,並且數據有效載荷將按照啓動程序活動的目的附加內容進行傳遞。
我能夠通過與FCM有效載荷發送自定義數據,然後在MainActivity的OnCreate解決這個()方法:
var someValue = Intent.GetStringExtra("YourKey");
// if result not null then handle how you like...
在我的情況,我想將用戶重定向到查看通知。
更新:
還有一種方法可以解決這個問題。
覆蓋OnMessageReceived方法...
[Service]
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
public class MyFirebaseMessagingService : FirebaseMessagingService
{
public override void OnMessageReceived(RemoteMessage message)
{
SendNotification(message?.Data);
}
void SendNotification(IDictionary<string, string> data)
{
// handle your data that got passed
}
}
,而不是在你的例子這樣做的,:
{
"noticiation" : {
"title" : "Test 456",
"text" : "Otra 123123"
}
}
傳遞數據,而不是:
{
"data" : {
"title" : "Test 456",
"text" : "Otra 123123"
}
}
OnMessageReceived現在被稱爲兩個當你的應用程序在後臺和在前臺。
請注意,此方法意味着您無法使用Firebase中的控制檯發送消息,因爲據我所知,它在有效內容中包含「通知」。
[如何在Firebase中的後臺應用程序中處理通知]的可能重複(http://stackoverflow.com/questions/37711082/how-to-handle-notification-when-app-in-background-in-firebase ) – X3Btel
請勿將圖片用於代碼/文本:https://meta.stackoverflow.com/questions/285551/why-not-to-upload-images-of-code-on-so-when-asking-a-問題 – SushiHangover
@ X3Btel我的問題是關於Xamarin而不是原生Android。有幾件事情完全不同。 –