转载:
http://blog.csdn.net/yuzhiboyi/article/details/8484771
https://my.oschina.net/youranhongcha/blog/196933
new Thread() { @Override
public void run() {
// TODO Auto-generated method stub
super.run();
NotificationManager manager = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification();
// 不会被清除
notification.flags = Notification.FLAG_NO_CLEAR;
notification.icon = R.drawable.main_icon_notification;
notification.tickerText = "XXX正在保护您的手机";
// 远程的view 我们的view对象 是要显示在另外一个进程里面 另外一个程序里面 所以就需要一个remote view
RemoteViews rv = new RemoteViews(getPackageName(),
R.layout.monitor_app);
rv.setTextViewText(R.id.textView1, "XXX正在保护您的手机");
rv.setProgressBar(R.id.progressBar1, 100, 0, false);
notification.contentView = rv;
Intent intent = new Intent(MonitorService.this,
SplashActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(
MonitorService.this, 0, intent,
Intent.FLAG_ACTIVITY_NEW_TASK);
notification.contentIntent = pendingIntent; manager.notify(2, notification);
} }.start();