通知栏的出现需要两个类:NotificationManager 和 Notification
private static final int HELLO_ID = 1;
private NotificationManager mNotificationManager ;
private Intent notificationIntent;
String ns = Context.NOTIFICATION_SERVICE;
mNotificationManager = (NotificationManager)getSystemService(ns);
int icon = R.drawable.froad_icon;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
Context context = getApplicationContext();
CharSequence contentTitle = "通知抬头";
CharSequence contentText = "通知内容";
notificationIntent = new Intent(this,FroadShop.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(HELLO_ID, notification);
mNotificationManager.cancel(HELLO_ID);