Android Notification使用及取消

时间:2023-03-10 01:22:57
Android Notification使用及取消
//发送通知
NotificationManager manger = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE);
Notification noti = new Notification(R.drawable.icon,"电话录音",System.currentTimeMillis());
Intent it = new Intent();
it.setClass(this, MainActivity.class);//点击通知后要跳向的页面
PendingIntent pi = PendingIntent.getActivity(this, 0, it, 0);
noti.setLatestEventInfo(this, "电话录音", "正在监听...", pi);
noti.defaults = Notification.DEFAULT_ALL;//有4种
manger.notify(, noti);// id=10
//取消
NotificationManager manger = (NotificationManager)this.getSystemService(NOTIFICATION_SERVICE);
manger.cancel();