Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I have used this tutorial (GCM Demo Application[^]) to run the sample gcm-server application.

I have successfully built both client and server side code.

Now, I got stuck on sending my own message to client application from server.

I have referred this link(Message[^]) to send my own MessageBuilder

So, I modified the code like this,

server side:-
Message msg = new Message.Builder().build();


to

Message msg = new Message.Builder()
          .collapseKey("collapseKey")
          .timeToLive(30)
          .delayWhileIdle(true)
          .addData("key1", "value1")
          .addData("key2", "value2")
          .build();


client side:-
@Override
    protected void onMessage(Context context, Intent intent) {
        Log.i(TAG, "Received message");
        String message = intent.getStringExtra("key2");
        //getString(R.string.gcm_message);
        displayMessage(context, message);
        // notifies user
        generateNotification(context, message);
    }


But Still I'm getting 'null' in client application. Please help me..

Thanks in Advance.
Posted
v3

Make sure the massages you sent were right.
 
Share this answer
 
IMHO you are trying to do too many things in your new "Message msg = ..." statement. Break that up into sequential steps and look at the result of each in the debugger.

If you were working on my project in the real world, I would not let you submit code that looked like that. Too complex, too difficult to debug (as verified by your current trouble). Packing as much code as possible into one line is not considered good style.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900