I can't receive message - Push Notification Service

0 votes


I followed this tutorial http://api.shephertz.com/tutorial/Push-Notification-Android/?index=pn-android

When I got in the third step " 3. Sending Message to User - From AppHQ Console ", my device can't receive any message.

There is a user in my AppHQ


This is my code

MainActivity => http://codeshare.io/MReh9

AndroidManifest.xml => http://codeshare.io/p4RLH

Please help me !

Thank you !

asked May 13, 2014 in App42 Cloud API-BaaS by guo (110 points)

1 Answer

0 votes
Best answer
Hi Guo,

Thanks for sharing all the files.

For my acknowledgement, You have passed the Credentials in App42API.initialize(this,       "<YOUR API KEY>","<YOUR SECRET KEY>"); in sending push notification.

And, Name for which you are sending push message is same as you registered with App42 because what i have seen in your code and image the name is not same.
answered May 13, 2014 by hs00105 (517 points)
selected Jun 16, 2014 by guo
In http://api.shephertz.com/tutorial/Push-Notification-Android/?index=pn-android

step 1 ~ step 2,we works fine, but in step 3, there are two lines of code, when we add those code into my code, we got error message below and app crushed

error line :
PushNotification pushNotification = pushNotificationService.sendPushMessageToUser(userName,message);

userName and the name registered with App42 are the same.

Are those two lines of code stacked in wrong place ?
our code : http://codeshare.io/MReh9

Can you help me !
Hey Guo,
1.Please don't make API call on UI Thread like :
2. You can use async API if you want to call on UI thread that is the issue :
  PushNotification pushNotification = pushnotificationService.sendPushMessageToUser("ideabus01","mymessage");

3 So you can Use async API to send Push to user::
    App42API.buildPushNotificationService().sendPushMessageToUser("ideabus01","mymessage", new App42CallBack() {
            public void onSuccess(Object arg0) {
                // TODO Auto-generated method stub
            public void onException(Exception arg0) {
                // TODO Auto-generated method stub

Please revert us in case of any query again.
Thanks for your reply !

for 3, this snippet  works fine, but we don't receive any message.

in function onResume() below

public void onResume() {
    String message = getIntent().getStringExtra(
    Log.d("MessageActivity-onResume", "Message Recieved :" + message);
    IntentFilter filter = new IntentFilter(
    registerReceiver(mBroadcastReceiver, filter);

we get message " null " and function onReceive() doesn't call.

public void onReceive(Context context, Intent intent) {

    // Right here do what you want in your activity
    String message = intent
    Log.i("MessageActivity-BroadcastReceiver", "Message Recieved "
            + " : " + message);
    ((TextView) findViewById(R.id.text)).setText(message);

How to receive the message from push notification ?
Sorry, I am a beginner.
Could give me sample about send and receive push notification ?

Thank you very much !
Hey Guo , You can use our sample Project on GitHub:

One more thing I want to ask do you follow proper steps for GCM integration.
1. If your server key that is submitted in AppHq console in Android Settings option for Push Notification doesn't match with your google project No .
2 In this case you can't receive any Push sent by console or Using API.
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com