你可以從你的活動開始一項服務。
第1步創建一個服務,殺死 簡單的一個。它只是殺死一個創建通知,並有他的特殊粘合劑。
public class KillNotificationsService extends Service {
public class KillBinder extends Binder {
public final Service service;
public KillBinder(Service service) {
this.service = service;
}
}
public static int NOTIFICATION_ID = 666;
private NotificationManager mNM;
private final IBinder mBinder = new KillBinder(this);
@Override
public IBinder onBind(Intent intent) {
return mBinder;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return Service.START_STICKY;
}
@Override
public void onCreate() {
mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNM.cancel(NOTIFICATION_ID);
}
}
第二步:將它添加到您的清單: 某處它添加插圖中的<應用>標籤。
<service android:name="KillNotificationsService"></service>
第三步:燒的通知之前,請務必創建服務,並使用靜態notificationid。
,直到服務重新啓動(1-5秒),這可能需要一點時間,但最終會啓動並殺死的通知。
您是否嘗試過在onStop或onPause中停止通知? –