android 让通知不自动消失

应用弹出通知时会自动消失,大概5秒钟,怎么让其一直显示在顶部呢

 if (VERSION.SDK_INT >= 26) {
            NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, NOTI_PUSH_CHANNEL, NotificationManager.IMPORTANCE_HIGH);
            notificationChannel.setDescription(context.getString(R.string.app_name));
            if (notificationManagerCompat != null) {
                notificationManagerCompat.createNotificationChannel(notificationChannel);
            }
        }

        Notification notification = (new Builder(context, CHANNEL_ID)).setSmallIcon(R.mipmap.ic_launcher)
                .setPriority(1)
                .setContentIntent(pendingIntent)
                .setCustomContentView(remoteViews)
                .setFullScreenIntent(pendingIntent, true).build();
        if (notificationManagerCompat != null) {
            notificationManagerCompat.notify(NOTIFICATION_REMINDER_ID, notification);
        }

这是相关属性,后来发现 少申请了一个权限

<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />

加上之后 就不会自动消失了

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容