how to use NOTIFICATION_SERVICE in android
I want to show a notification after receiving a WAP push message in my phone.I know that NOTIFICATION_SERVICE is i need to be used. But i don't know how to use this. Please help me to overcome this problem. I am able to receive the message in my phone and it is printing in the log correctly. Written some code for showing the notification but it is not working. Attaching the code along with please have a look on it and expecting a proper guiding on this.
private void showNotification(String text,Context con) {
Notification n = new Notification();
n.flags |= Notif开发者_运维知识库ication.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);
}
hard to answer without knowing exactly what your problem is (ie do you get an error etc..) but you could try this:
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);
}
精彩评论