0
我在C#Xamarin.Android項目上實施了推送通知,就像他們在官方Firebase文檔中一樣。RuntimeException在收到通知後拋出
可以使用Firebase控制檯發送通知。現在我試圖從另一個C#服務發送消息。設備監視器說,GCM消息已發送。
見Android設備監視郵件:http://imgur.com/a/wNOV3
這裏是我的代碼。爲何會發生這種情況?
AndroidManifest.xml中
<application android:label="myApp" android:icon="@drawable/icon">
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
<service android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
</application>
MyFirebaseMessagingService.cs
[Service]
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
public class MyFirebaseMessagingService : FirebaseMessagingService
{
const string TAG = "MyFirebaseMsgService";
public MyFirebaseMessagingService()
{
Log.Debug(TAG, "Service called");
}
public override void OnMessageReceived(RemoteMessage message)
{
string msg = message.GetNotification().Body;
Log.Debug(TAG, msg);
}
}
我在MyApp.Droid.MyFirebaseMessagingService得到一個AndroidRuntime錯誤工作。 OnMessageReceived與此配置 – localhorst27
你可以發佈你的日誌? – Leze
現在有效。但是,如果應用程序是開放的,那麼沒有通知。如果該應用已關閉,則可以使用。 – localhorst27