【问题标题】:RuntimeException throwed after receiving a notification收到通知后抛出 RuntimeException
【发布时间】:2017-04-06 09:44:57
【问题描述】:

我在我的 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);    
    }
}

【问题讨论】:

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


    【解决方案1】:

    我用这个清单配置让它工作

    <?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>
    

    【讨论】:

    • 我在 MyApp.Droid.MyFirebaseMessagingService.OnMessageReceived 使用此配置收到了 AndroidRuntime 错误
    • 你能发布你的日志吗?
    • 现在可以使用了。但是,如果应用程序已打开,则没有通知。如果应用程序关闭,它可以工作。
    猜你喜欢
    • 2015-01-25
    • 2023-03-24
    • 2017-07-26
    • 1970-01-01
    • 1970-01-01
    • 2018-07-10
    • 2011-10-02
    • 2012-11-23
    • 1970-01-01
    相关资源
    最近更新 更多