收到通知后抛出RuntimeException

时间:2017-04-06 09:44:58

标签: c# firebase xamarin xamarin.android firebase-cloud-messaging

我在C#Xamarin.Android项目上实现了推送通知,就像他们在官方firebase文档中那样。

可以使用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);    
    }
}

1 个答案:

答案 0 :(得分:0)

我使用此清单配置

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.xxxxx.xxxx" android:versionName="1.0.0" android:versionCode="2">
    <uses-sdk android:minSdkVersion="15" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <application android:icon="@drawable/icon" android:label="XX xXx">
        <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" />
                <category android:name="${applicationId}" />
            </intent-filter>
        </receiver>
    </application>
</manifest>