Android 通知不消失
创始人
2024-08-19 01:00:24
0次

要实现Android通知不消失的功能,可以通过以下方法:

方法一:设置通知的标志位

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
        .setSmallIcon(R.drawable.ic_notification)
        .setContentTitle("Notification Title")
        .setContentText("Notification Content")
        .setPriority(NotificationCompat.PRIORITY_HIGH)
        .setOngoing(true); // 设置为持续通知,不会被滑动或清除按钮移除

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(notificationId, builder.build());

方法二:设置通知的重要性

NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "Channel Name", NotificationManager.IMPORTANCE_HIGH);
channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); // 在锁屏状态下可见
channel.setSound(null, null); // 不播放通知声音
channel.enableVibration(false); // 禁用震动

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
        .setSmallIcon(R.drawable.ic_notification)
        .setContentTitle("Notification Title")
        .setContentText("Notification Content")
        .setPriority(NotificationCompat.PRIORITY_HIGH)
        .setChannelId(CHANNEL_ID);

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.createNotificationChannel(channel);
notificationManager.notify(notificationId, builder.build());

以上两种方法可以根据需求选择其中一种或结合使用。需要注意的是,通知不消失可能会干扰用户体验,因此在使用时应慎重考虑。

相关内容

热门资讯

一分钟秒懂辅助!闲来宁夏麻将辅... 一分钟秒懂辅助!闲来宁夏麻将辅助透视挂,九剑封天确实有外挂,好像有挂方法1、操作简单,无需闲来宁夏麻...
玩家必备科普透视挂!心动碰胡辅... 玩家必备科普透视挂!心动碰胡辅助透视挂,欢乐赣游XF确实有外挂,其实有挂辅助心动碰胡透视方法中分为三...
推荐一款开挂!美猴王辅助透视挂... 推荐一款开挂!美猴王辅助透视挂,北极熊真的是有外挂,果然有挂分析1.美猴王 选牌创建新账号,点击进入...
据了解辅助!掌乐宝辅助透视挂,... 据了解辅助!掌乐宝辅助透视挂,天天爱滁州麻将确实有外挂,竟然有挂方针1、金币登录送、破产送、升级送、...
一分钟了解辅助!洛阳杠兹辅助透... 一分钟了解辅助!洛阳杠兹辅助透视挂,百乐麻将确实有外挂,切实有挂秘笈1)洛阳杠兹辅助插件:进一步探索...
热门推荐开挂!天天微友辅助透视... 热门推荐开挂!天天微友辅助透视挂,小闲巴渝棋牌真的是有外挂,一贯有挂解密1、很好的工具软件,可以解锁...
来一盘透视挂!新九五辅助透视挂... 来一盘透视挂!新九五辅助透视挂,逍遥湖北麻将真的是有外挂,竟然有挂分析1、实时新九五透视辅助更新:用...
现有说明如下辅助!小南娱乐辅助... 现有说明如下辅助!小南娱乐辅助透视挂,蜀州麻将海宁是有外挂,果然有挂教程1、打开软件启动之后找到中间...
重大通报透视挂!28圈辅助透视... 重大通报透视挂!28圈辅助透视挂,同道麻将真的是有外挂,一直有挂透视1、进入到同道麻将是否有挂之后,...
玩家必备攻略辅助!川南九九辅助... 玩家必备攻略辅助!川南九九辅助透视挂,凤月是有外挂,果然存在有挂1、下载好川南九九正确养号方法之后点...