3

J'ai réussi à configurer le code pour exécuter GCM sur phonegap sur une application Android. J'ai réussi à sécuriser l'identifiant d'enregistrement du combiné et à envoyer un message à l'application en utilisant cet identifiant dans un script PHP. Mon seul problème est que le message s'affiche comme une alerte javascript alors que l'application est ouverte, et je cherche à avoir un message envoyé à l'appareil, mais ne montrant pas l'icône sur la barre de notifications supérieure.android Notifications push GCM

**> fait est icône possible montrant la barre haut dans l'appareil Android

Est-ce que quelqu'un sait si le plugin GCM pour Phonegap est capable de le faire? **

J'utilisant C2DM-Phonegap. https://github.com/marknutter/GCM-Cordova

s'il vous plaît aidez-moi des amis ...

+0

Pouvez-vous reformuler votre question pour être plus clair? Essayez-vous d'afficher une icône dans la barre de notification (en haut) lors de la réception d'une notification push? – acj

+0

Oui, quand une notification push est reçue alors pas d'icône dans la barre de notification (en haut) – Patel

+0

La réponse de toadzky ci-dessous est correcte. La plupart des bibliothèques vous permettent de spécifier l'action à effectuer lorsqu'une notification push est reçue. – acj

Répondre

2

La bibliothèque que vous utilisez ce qui doit Précise faire lorsqu'un message est reçu. Vous pouvez modifier leur code pour faire ce que vous voulez ou lancer votre propre GCIntentService.

0

La méthode la plus rapide consiste à ajouter le code suivant à GCMIntentService.java dans la fonction onMessage. Le plugin GCM que vous utilisez reçoit uniquement le message GCM, mais vous devez déclencher des notifications par vous-même. Vous pouvez également essayer un plugin cordova pour les notifications de la barre d'état.

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); 
0

s'il vous plaît vérifier ce code

generateNotification private static void (contexte de contexte, le message String) { int icône = 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); 


} 
Questions connexes