android - 正在进行的通知可以忽略

标签 android

我想显示一个不可关闭的通知,并且仅在以编程方式延迟一段时间后才将其关闭。我尝试了以下方法:

RemoteViews bigView = new RemoteViews(context.getPackageName(),
            R.layout.big_notification);



    NotificationCompat.Builder builder = new 
   NotificationCompat.Builder(context)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle(title)
            .setContentText(text)
            .setDefaults(Notification.DEFAULT_ALL)
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setCustomHeadsUpContentView(bigView)
            .setTicker("aaa")
            .setOngoing(true);


    notificationManager.notify(id, builder.build());
    removeNotification(notificationManager, id);
}

private static void removeNotification(final NotificationManager notificationManager, final int id) {
    Handler handler = new Handler();
    long delayInMilliseconds = 4000;
    handler.postDelayed(new Runnable() {
        public void run() {
            notificationManager.cancel(id);
        }
    }, delayInMilliseconds);
}

但是通知可以被用户刷掉……有什么想法吗?

最佳答案

试试这个:

notification.flags = Notification.FLAG_NO_CLEAR;

关于android - 正在进行的通知可以忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45983926/

相关文章:

java - 找不到符号构造函数ArrayAdapter(android.content.Context,int,java.lang.String[])

android - 为什么我不能将 mopub-android-sdk 添加为库?

android - 在选项卡 View 中,我想刷新 Fragment 每次更改

android - 如何显示pdf内容?

android - Android 是否计划支持 Java7?

android - HardwarePropertiesManager 不工作

java - 从 Firestore 获取数据时 Android 加载图标

android - 如何将所有应用程序数据迁移到不同的设备。无根

android - 使用 XmlPullParser 从元素获取 xml 字符串数据

android - 流音频文件,以便在Android中使用Google Drive API从Google Drive播放