认为这根本不是问题,但仍然如此.
无论我做什么,“我的服务”通知都不想滑动清除.
我有一个进度通知,该通知在服务中使用startForeground(id,Notification)启动.
这是我的构建方式:
public Notification createErrorNotification(String message) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext());
Intent showAppIntent = new Intent(getApplicationContext(), MainActivity.class);
showAppIntent.setAction(Intent.ACTION_MAIN);
showAppIntent.addCategory(Intent.CATEGORY_LAUNCHER);
PendingIntent pendingShowAppIntent = PendingIntent.getActivity(getApplicationContext(), 10,
showAppIntent, PendingIntent.FLAG_CANCEL_CURRENT);
builder.setContentTitle(getString(R.string.label_download_error))
.setWhen(0)
.setContentText(message)
.setContentIntent(pendingShowAppIntent)
.setAutoCancel(true)
.setOngoing(false)
.setSmallIcon(R.drawable.ic_launcher);
return builder.build();
}
在某些时候,如果发生错误,我将进度通知替换为所描述的错误通知,并禁用“进行中”等功能.
我也完全停止服务:
private void stopService() {
stopSelf();
taskThread.stopLooper();
downloadHandler.stopExecution();
downloadHandler = null;
taskThread = null;
}
并致电
stopForeground(false);
false-因为我希望通知在屏幕上保留并被用户关闭.
但是清除滑动功能根本行不通.
如果我调用stopForeground(true)-通知已正确删除.
有人有任何想法我在这里做错了吗?