1 创建NotificationMananger 对象,负责发出和取消通知。
NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
2 初始化Notification设置图片资源,显示的文本、时间、能否取消
Notification n =
new
Notification(R.drawable.chat,
"Hello,there!"
, System.currentTimeMillis());
3 展示通知
nm.notify(0,n);
4 取消通知
nm.cancelNotify(0,n);
public class MainActivity extends Activity implements OnClickListener {
private Notification notification;
private NotificationManager nManager;
private Notification notification;
private NotificationManager nManager;