3

I have successfully set up the code to run GCM over phonegap on an android app. I have managed to secure the handset registration ID and able to send a message to the app using this ID in a PHP script. My only problem is that the message displays as a javascript alert whilst the app is open, and I am looking to have message sent to the handset's but not showing icon on top notifications bar .

**> does is possible showing icon on top bar in android device

Does anyone know if the GCM plugin for Phonegap is capable of doing this?**

I have using C2DM-Phonegap. https://github.com/marknutter/GCM-Cordova

please help me friends...

Patel
  • 543
  • 4
  • 20
  • Can you rephrase your question to be clearer? Are you trying to show an icon in the notification (top) bar when a push notification is received? – acj Oct 24 '12 at 14:13
  • Yes, when a push notification is received then not show an icon in the notification (top) bar – Patel Oct 25 '12 at 04:43
  • toadzky's answer below is correct. Most libraries will let you specify the action to perform when a push notification is received. – acj Oct 25 '12 at 12:20

4 Answers4

4

The library you are using specifies what needs to be done when a message is received. You can either modify their code to do what you want or roll your own GCMIntentService.

please refer this links :

https://github.com/phonegap-build/PushPlugin

https://build.phonegap.com/plugins/324

user3076732
  • 88
  • 1
  • 8
2

The library you are using specifies what needs to be done when a message is received. You can either modify their code to do what you want or roll your own GCMIntentService.

toadzky
  • 3,806
  • 1
  • 15
  • 26
0

The quickest way is to add the following code to GCMIntentService.java into the onMessage function. The GCM plugin you are using only receives the GCM message, but you have to trigger notifications on your own. You can also try a cordova plugin for status bar notifications.

 protected void onMessage(Context context, Intent intent) {
Log.d(TAG, "onMessage - context: " + context);

// Extract the payload from the message
Bundle extras = intent.getExtras();
if (extras != null) {
    String message = extras.getString("message");
    String title = extras.getString("title");

    Notification notif = new Notification(R.drawable.ic_launcher, message, System.currentTimeMillis() );
    notif.flags = Notification.FLAG_AUTO_CANCEL;
    notif.defaults |= Notification.DEFAULT_SOUND;
    notif.defaults |= Notification.DEFAULT_VIBRATE;

    Intent notificationIntent = new Intent(context, SomeActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    notif.setLatestEventInfo(context, "Title of notification", message, contentIntent);
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);
    mNotificationManager.notify(1, notif);
cosmicnag
  • 103
  • 1
  • 7
0

please check this code

private static void generateNotification(Context context, String message) { int icon = R.drawable.ic_launcher;

       // here is your icon drawable instead of ic_launcher

    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager)
            context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context.getApplicationContext(), devicephp.class);
    // set intent so it does not start a new activity

    notificationIntent.putExtra("msg", message);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
            Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent =
            PendingIntent.getActivity(context, 0, notificationIntent, 0);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(0, notification);


}
jigspatel
  • 400
  • 3
  • 14