OnMessageReceived 未被调用

OnMessageReceived is not invoked

我正在尝试使用 xamarin 通知。 对于 android,我遵循了以下步骤:https://developers.google.com/cloud-messaging/android/client 客户端显示通知。 在我的服务器端,我正在使用 pushSharp 插件,自从服务器端发送消息以来,一切看起来都运行良好。 问题是我没有在 phone 上收到通知。当我处于调试模式时,我的应用程序会崩溃,有时当应用程序处于后台时也会崩溃。正如我所看到的这个方法:

 public override void OnMessageReceived(string from, Bundle data){//Extract the message received from GCM:
        var message = data.GetString("message");
        Log.Debug("MyGcmListenerService", "From:    " + from);
        Log.Debug("MyGcmListenerService", "Message: " + message);

        //Forward the received message in a local notification:
        SendNotification(message);}

它根本没有被调用。 我的清单如下:

<service android:name="com.my_companyname_goes_here.app_name_goes_here.android.MyGcmListenerService" android:exported="false">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        </intent-filter>
    </service>

我尝试在网上搜索答案,但 none 解决了我的问题: 等 任何形式的帮助将不胜感激。

编辑: 这是我的 json

{
"message": "test",
"vibrate": 1,
"sound": 1
}

你可以看看Xamarin官方文档Xamarin Google Cloud Messaging :

https://developer.xamarin.com/guides/android/application_fundamentals/notifications/remote-notifications-with-gcm/

这是关于上述文件的示例:

https://developer.xamarin.com/samples/monodroid/RemoteNotifications/

此外,请确保 Google Play Services 在您的设备中可用。

更新:

请尝试像这样添加服务属性:

[Service(Exported = false), IntentFilter(new[] { "com.google.android.c2dm.intent.RECEIVE" })]
public class MyGcmListenerService : GcmListenerService
{
    ...
}