简体   繁体   中英

OnMessageReceived is not invoked

I am trying to get to work with xamarin notifications. For android I have followed these steps: https://developers.google.com/cloud-messaging/android/client for the client side to show the notification. On my server side I am using pushSharp plugin and everything is looks to work fine since the message from the server side is sent. The problem is that I don't get the notification on my phone. My app just crushes when I'm in debug mode or sometimes times it crushes when the app is in background too. As I can see this method :

 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);}

it's not called at all. My manifest is as followed :

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

I tried searching the web for an answer but none as followed solved my problem : GcmListenerService is not called When Application is in Background Xamarin GCM OnMessageReceived is not called ect etc. Any kind of help would be appreciated.

Edit : This is my json

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

You could read the Xamarin official document Xamarin Google Cloud Messaging :

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

Here is the sample about the above document :

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

Also, please make sure Google Play Services is available in your device.

Update :

Please try to add the service attribute like this :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM