1

I have tried sending notification JSON to GCM server using GCM-SERVER jar in plain text format and succeed but unable to find how can send the request in json format using same jar... please provide any document link for gcm-server jar or any help will be appreciated...

code is following that i have tried in plain text format ...

import com.google.android.gcm.server.Message;
import com.google.android.gcm.server.Result;
import com.google.android.gcm.server.Sender;

private static final String GOOGLE_SERVER_KEY = "AIzaSyCIiiADfyS5dDuKk65Auk1_qhr-vruv2-0";
static final String MESSAGE_KEY = "message";

public static boolean PushNotificationsInPlainText(String type, String device,String content)    {

    Result result = null;
    String regId = "APA91bGpY6NdmK22dCId1LIyHLY3RKYmrFu3A5hyYHqNVvtP1puS0ITLC73fZ3XBgZqnt_AHYiH8C9Rkk37yazTCLkw0mJymxZUPZTtICtIJY5drM_ZOzpFTF71V0TkiHCQ-k3QGV7bv";
    Sender sender = new Sender(GOOGLE_SERVER_KEY);
    Message message = new Message.Builder().timeToLive(30)
                   .delayWhileIdle(true).addData(MESSAGE_KEY, content).build();
    System.out.println("regId: " + regId);
    try {
        result = sender.send(message, regId, 1);
    } catch (IOException e) {
        System.out.println(result);
        e.printStackTrace();
    }
    return true;
}
Rajesh Jadav
  • 12,801
  • 5
  • 53
  • 78
  • Why don't you use GCMSender from [this](https://developers.google.com/cloud-messaging/android/start) example? – Bilal Haider Oct 02 '15 at 06:55
  • Yea.. I am using it but here message is building through a palin text content and my requirement is as a json (key-value) format.... – Vinit Kumar Jain Oct 02 '15 at 19:10
  • @ Bilal Haider... i have gone through the link you have provided...that gcmsender is related to android ... i am asking about from app server side..any other help will be appreciated... – Vinit Kumar Jain Oct 05 '15 at 06:56
  • Answer in this [link](http://stackoverflow.com/a/21871046/4600792) might help you. Can you tell any use case for this type of application? – Bilal Haider Oct 05 '15 at 10:20
  • You can use a JSONObject the way [this poster](http://stackoverflow.com/questions/32894187/gcm-topics-global-works-but-to-register-id-doesnt) did. Or some other library like Jackson as used [here](http://hmkcode.com/android-google-cloud-messaging-tutorial/). – Koh Oct 05 '15 at 18:01

0 Answers0