PushSharp:Android GCM Push Notification received without push message

13,526

Solution 1

I tried using different code available around.. but none of those were working..

finally I tried https://stackoverflow.com/a/11651066/1005741 and it works like a charm!

Solution 2

I encountered the same issue, where I received an empty message. My code was a bit different and i was using different libraries: the client was wrapped with phonegap pushPlugin ,and the server code is as follows :

...
// com.google.android.gcm.server.Sender.Sender(String key)‬
gcmSender = new Sender(androidAPIkey);
// com.google.android.gcm.server.Message
Message message = new Message.Builder().addData("alert", "test message" /*notif.getAlert()*/).build();
Result result = gcmSender.sendNoRetry(message, /* device token */ notif.getToken());
nr.add(result, notif.getToken());
...

The reason why my messages where empty is due to the fact that phonegap looks for "message" , "msgcnt" or "soundname" while parsing the extras from the intent. So, this was the solution in my case :

Message message = new Message.Builder().addData("message", notif.getAlert()).build();

Hope this will help someone

Share:
13,526
hriziya
Author by

hriziya

Updated on June 05, 2022

Comments

  • hriziya
    hriziya almost 2 years

    I am using PushSharp library to send push notification from my application.

    PushService push = new PushService();
    var reg_id_d = "APA91bETd-LsqnZjA-HKrnBOY3FbEhmWchpiwuhRkiv4gUdGDuvwDRB7YURICZ131XppDAUNUBLGe_vEPkQ-JR8UaVX7Y-NCkEfastCBLIYcUoFtt5cPafeKXHywi0WGDYW33ZQqr3oy";
    var project_id_d = "482885626272";
    var api_key_d = "AIzaSyAbh7R5KQR3KM7W_y-yS-Ao-JNiihNz7tE"; // "AIzaSyDcKfuW77GTwA46L6sqD41YhGf2j5S8o2w";
    var package_name_d = "com.get.deviceid";
    
    push.StartGoogleCloudMessagingPushService(new GcmPushChannelSettings(project_id_d, api_key_d, package_name_d));
    push.QueueNotification(NotificationFactory.AndroidGcm()
                    .ForDeviceRegistrationId(reg_id_d)
                    .WithCollapseKey("NONE")
                    .WithJson("{\"alert\":\"Alert Text!\",\"badge\":\"1\"}"));
    

    I am getting notification on my device but with blank message..

    I have tried with sever code available in C# to send GCM push notification, but getting same problem of having blank message.

    I tried using PHP to send notification. and it is working as expected. so, I am not sure what is wrong in my above code. Can anyone please help me on this?