I can't receive message - Push Notification Service

0 votes

Hi,

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

http://666kb.com/i/cob6kas1dk681l78z.jpg

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
Hi,
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
http://666kb.com/i/cok1k50st3qt4gicz.jpg

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() {
           
            @Override
            public void onSuccess(Object arg0) {
                // TODO Auto-generated method stub
               
            }
           
            @Override
            public void onException(Exception arg0) {
                // TODO Auto-generated method stub
               
            }
        });

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

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

in function onResume() below

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


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


@Override
public void onReceive(Context context, Intent intent) {

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


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:
https://github.com/shephertz/App42-Android-Push-Sample

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
...