【发布时间】: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