intent.getStringExtra("payload") returns null

3,316 views
Skip to first unread message

shirish

unread,
May 22, 2011, 6:24:58 AM5/22/11
to android-c2dm
Hi,

I have just signed up for the c2dm service and when I send the message
to my mobile using
curl --header "Authorization: GoogleLogin auth=XXXXXX" "https://
android.apis.google.com/c2dm/send" -d registration_id=XXXX -d "data.
message=Hello world" -d collapse_key=something -k

I get a response to the client but I dont get payload

System.out.println( intent.getStringExtra("from")); // I get the
email ID which I registered over here
System.out.println( intent.getStringExtra("collapse_key")); //
"something " as specified
System.out.println( intent.getStringExtra("payload")); //but this
gives me null

Can any one help me out here.

Thanks & Regards,
Shirish.

abdulw...@gmail.com

unread,
May 22, 2011, 7:16:35 AM5/22/11
to androi...@googlegroups.com

Hi
When you receive message it comes in the form of intent so just add two lines in your code:
Bundle extras=intent.getExtras();
//check if extras is not null
If(extras!=null)
String msg=(string)extras.get("messgae");//remember here message is the key that you send from the server...
Wish it would help you


onReceive()
Sent from my Nokia phone

shirish

unread,
May 22, 2011, 9:04:37 AM5/22/11
to androi...@googlegroups.com
Thanks it worked :).
--
Shirish Reddy P
(Student)
Indian Institute Of Information Technology, Allahabad
Mob No. +919651418099

abdulw...@gmail.com

unread,
May 22, 2011, 11:01:30 AM5/22/11
to androi...@googlegroups.com
You are welcome!!
For more info on c2dm follow
http://waheedtechblog.blogspot.com

Enjoy..

Charles Moore

unread,
Dec 16, 2012, 10:20:47 AM12/16/12
to androi...@googlegroups.com, abdulw...@gmail.com
Hi
Please I've the exact same problem. I've tried you suggestion, it hasn't worked for me. Is there something else I should do? Please!

Intent intent=getIntent();
Bundle extra=intent.getExtras();
if(extra !=null);
//String options=intent.getStringExtra(CurrentLectureActivity.TRANSFER_OPMESSAGE);// what i did..
String options=(String)extra.get(CurrentLectureActivity.TRANSFER_OPMESSAGE);//Your suggestion
Reply all
Reply to author
Forward
0 new messages