记录android 通知消息
NotificationManager 通知消息管理(发送,取消)
notifcation 消息肉容的设置,提醒音乐;
activity1中的onCreate
String title ="测试消息";
String content ="通知工作日期到期"; PendingIntent intent = PendingIntent.getActivity(MainActivity.this, 0, new Intent(MainActivity.this, SecActivity.class), 0); //title标题栏显示的文字 Notification notifcation = new Notification(R.drawable.ic_launcher, title, System.currentTimeMillis()); //设置具体内容和标题 notifcation.setLatestEventInfo(MainActivity.this, title, content, intent); //设置默认声音 notifcation.defaults = Notification.DEFAULT_SOUND; //通知管理 NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); //发送通知 notificationManager.notify(2, notifcation);
SecActivity中的onCreate
NotificationManager nm=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
//取消通知 nm.cancel(1);