NotificationManager mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
// Set the icon, scrolling text and timestamp 设置可以在状态栏上显示的图标和提示信息
Notification notification = new Notification(R.drawable.stat_sample, text,
System.currentTimeMillis());
// The PendingIntent to launch our activity if the user selects this notification
//用户在状态栏点击相应的notify可以发送的Intent(连接到相应的activity)
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, ForegroundServiceController.class), 0);
// Set the info for the views that show in the notification panel.
//状态栏的notify展开后显示的文本信息
notification.setLatestEventInfo(this, getText(R.string.local_service_label),
text, contentIntent);
mNM.notify(R.string.foreground_service_started, notification);//使用R.string.foreground_service_started 是因为它是一个唯一ID
//取消notify
mNM.cancel(id);//id=R.string.foreground_service_started 之前定义的一个唯一ID
Notification 的使用
最新推荐文章于 2024-08-22 08:42:48 发布