2011-05-28 5 views
2

Je veux afficher une notification après avoir reçu un message push WAP sur mon téléphone. Je sais que NOTIFICATION_SERVICE est nécessaire. Mais je ne sais pas comment l'utiliser. S'il vous plaît aidez-moi à surmonter ce problème. Je suis en mesure de recevoir le message dans mon téléphone et il imprime correctement dans le journal. Écrit du code pour montrer la notification mais cela ne fonctionne pas. Joindre le code avec s'il vous plaît jeter un coup d'oeil sur elle et s'attendre à un bon guidage à ce sujet.comment utiliser NOTIFICATION_SERVICE dans android

private void showNotification(String text,Context con) { 

    Notification n = new Notification(); 

    n.flags |= Notification.FLAG_SHOW_LIGHTS; 
    n.flags |= Notification.FLAG_AUTO_CANCEL; 

    n.defaults = Notification.DEFAULT_ALL; 

    n.icon = R.drawable.ic_sms_wap; 
    //n.when = System.currentTimeMillis(); 

    // Simply open the parent activity 

    // Change the name of the notification here 
    //n.setLatestEventInfo(this, NOTIF_TITLE, text, pi); 

    mNotifMan.notify(NOTIF_CONNECTED, n); 
} 
+0

-vous obtenez une erreur? avez-vous initialisé mNotifMan? – jkhouw1

+0

N'avoir aucune erreur. La notification ne montre pas que c'est le problème. Oui j'ai initialisé mNotifMan. Je vais essayer avec la modification que vous avez faite. – Kamalone

+0

Désolé pour le commentaire ci-dessus. J'obtiens ne peut pas trouver l'erreur de symbole pour NOTIFICATION_SERVICE. Mon initialisation est comme mNotifMan = (NotificationManager) getSystemService (NOTIFICATION_SERVICE); – Kamalone

Répondre

6

difficile de répondre sans savoir exactement ce que votre problème est (c.-à-vous obtenez une erreur etc ..) mais vous pouvez essayer ceci:

private void showNotification(String text,Context con) { 
    if (mNotifMan==null) { 
      mNotifMan=(NotificationManager) con.getSystemService(NOTIFICATION_SERVICE); 
    } 
    Notification n = new Notification(R.drawable.ic_sms_wap,text,System.currentTimeMillis()); 

    n.flags |= Notification.FLAG_SHOW_LIGHTS; 
    n.flags |= Notification.FLAG_AUTO_CANCEL; 

    n.defaults = Notification.DEFAULT_ALL; 

    // n.icon = R.drawable.ic_sms_wap; 
    // n.when = System.currentTimeMillis(); 

    // Simply open the parent activity 

    // Change the name of the notification here 
    //n.setLatestEventInfo(this, NOTIF_TITLE, text, pi); 

    mNotifMan.notify(null,NOTIF_CONNECTED, n); 
} 
+0

mNotifMan = (NotificationManager) getSystemService (NOTIFICATION_SERVICE); – Kamalone

+0

erreur en cours d'obtention du symbole NOTIFICATION_SERVICE – Kamalone

+3

sur quoi sdk vous construisez-vous? NOTIFICATION_SERVICE doit être une constante android.content.Context.NOTIFICATION_SERVICE qui résout en "notification" – jkhouw1