当前位置: 代码迷 >> Android >> Notification 如何常驻
  详细解决方案

Notification 如何常驻

热度:15   发布时间:2016-05-01 20:58:23.0
Notification 怎么常驻?
在android刚开机时,启动 Notification ,每次都是几秒后都消失,请问下怎么让Notification一直在?
部分代码:

public class AngelDaemon extends IntentService 
{
  public void onCreate() {
  super.onCreate();

Notification notification = new Notification(R.drawable.status, getText(R.string.notification),
System.currentTimeMillis());

Log.v("Angel", "Notification ");
Intent notificationIntent = new Intent(this, AndroidDiaOperation.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

Log.v("Angel", "PendingIntent ");

notification.setLatestEventInfo(this, getText(R.string.notification),
getText(R.string.notification), pendingIntent);
Log.v("Angel", "setLatestEventInfo ");

startForeground(ONGOING_NOTIFICATION, notification);
  }

}

本来想在protected void onHandleIntent(Intent intent) 这里启动延时,但是都会被android给自动杀掉.


------解决方案--------------------
设置一个属性,不让系统清除通知。楼主可以查看一下相关的API,就知道了。
先查API是个好习惯。API解决不了,再问。这样收获更大。
------解决方案--------------------
探讨

设置一个属性,不让系统清除通知。楼主可以查看一下相关的API,就知道了。
先查API是个好习惯。API解决不了,再问。这样收获更大。
  相关解决方案