我发送未扩展任何上下文的类的构造函数。
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
myNotification = new NotificationCompat.Builder(context)
.setSmallIcon(icon)
.setContentTitle(context.getResources().getString(R.string.app_name))
.setContentText(context.getResources().getString(R.string.app_name))
.setWhen(when)
.setTicker(context.getResources().getString(R.string.app_name))
.setDefaults(Notification.FLAG_NO_CLEAR);然后我通过RemoteViews发送一些数据,最后
Intent notificationIntent = new Intent(context, Menu_Activity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
contentView.setOnClickPendingIntent(R.id.layoutNotification, contentIntent);
myNotification.setContent(remoteView);
myNotification.setOngoing(false);
myNotification.setAutoCancel(false);
myNotification.setPriority(Notification.PRIORITY_HIGH);
myNotification.setContentIntent(contentIntent);
myNotificationManager.notify(NOTIFICATION_ID, myNotification.build());但我需要设置这个通知,它将不可能删除通过滑动它的一边。现在每一次我都可以通过滑动删除它。怎么让它失效?
谢谢
发布于 2013-07-23 23:58:09
通知生成器有一个方法setOngoing。将其设置为true,使通知成为用户不能拒绝的持续通知。
设置这是否是“正在进行的”通知。用户不能拒绝正在进行的通知,因此您的应用程序或服务必须负责取消它们。它们通常用于指示用户正在积极参与的后台任务(例如,播放音乐)或以某种方式挂起,从而占用设备(例如,文件下载、同步操作、活动网络连接)。
发布于 2013-10-06 08:52:51
您只需要使用setOngoing(真)。删除setAutoCancel(假)行。
同时使用setOngoing()和setAutoCancel()方法对我不起作用(没有显示通知)。
https://stackoverflow.com/questions/17821758
复制相似问题