Android Oreo通知显示在状态栏中,但不显示在点通知中。
创始人
2024-08-14 22:00:54
0

要实现Android Oreo通知在状态栏中显示,但不在锁屏和点通知中显示,可以使用以下代码示例:

// 创建通知渠道
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    String channelId = "channel_id";
    CharSequence channelName = "Channel Name";
    int importance = NotificationManager.IMPORTANCE_HIGH;
    NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName, importance);
    notificationChannel.enableLights(true);
    notificationChannel.setLightColor(Color.RED);
    notificationChannel.enableVibration(true);
    notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);

    NotificationManager notificationManager = getSystemService(NotificationManager.class);
    notificationManager.createNotificationChannel(notificationChannel);
}

// 构建通知
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "channel_id")
    .setSmallIcon(R.drawable.ic_notification)
    .setContentTitle("标题")
    .setContentText("内容")
    .setPriority(NotificationCompat.PRIORITY_HIGH)
    .setVisibility(NotificationCompat.VISIBILITY_SECRET)
    .setAutoCancel(true);

// 发送通知
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(notificationId, builder.build());

上述代码首先创建了一个通知渠道,并设置了锁屏可见性为VISIBILITY_SECRET,然后使用NotificationCompat.Builder构建通知,并将其锁屏可见性设置为VISIBILITY_SECRET。最后,使用NotificationManagerCompat发送通知。

这样设置后,通知将在状态栏中显示,但在锁屏和点通知中将不会显示。请注意,上述代码中的channel_id需要与通知渠道的ID相匹配。

相关内容

热门资讯

四分钟技巧!喜扣打筒子真的有挂... 四分钟技巧!喜扣打筒子真的有挂吗,aapoker有有规律(详细透视辅助助手教程)科技教程也叫必备教程...
1分钟教学!悠闲麻将川南四川人... 1分钟教学!悠闲麻将川南四川人民棋牌有挂吗,pokerworld有挂(详细透视辅助黑科技教程)准备好...
七分钟总结!琼崖海南麻将怎么提... 这是一款非常优秀的琼崖海南麻将怎么提高胜率 ia辅助检测软件,能够让你了解到琼崖海南麻将怎么提高胜率...
两分钟攻略!掌心麻将软挂神器,... 两分钟攻略!掌心麻将软挂神器,wpk透视辅助哪里下载(详细透视辅助神器教程);实战中需综合运用上述技...
5分钟介绍!星星武汉麻将有老千... 5分钟介绍!星星武汉麻将有老千吗,微扑克软件发牌原理(详细透视辅助神器教程);星星武汉麻将有老千吗黑...
1分钟了解!广东雀神麻雀调胜率... 广东雀神麻雀调胜率新手教程相关信息汇总(需添加指定薇757446909获取下载链接);1分钟了解!广...
八分钟介绍!微信多乐跑得快能不... 八分钟介绍!微信多乐跑得快能不能开挂,wepoke透明挂辅助软件是真的(详细透视辅助助手教程);(需...
两分钟详情!万圣节消除大作战有... 两分钟详情!万圣节消除大作战有挂吗,轰趴大菠萝辅助器(详细透视辅助神器教程);玩家必备必赢加哟《13...
九分钟攻略!牵手麻将怎么才能赢... 这是一款非常优秀的牵手麻将怎么才能赢 ia辅助检测软件,能够让你了解到牵手麻将怎么才能赢中牌率当中全...
一分钟黑科技!逸趣吉安麻将有挂... 一分钟黑科技!逸趣吉安麻将有挂吗,wepoke存在外 挂(详细透视辅助挂教程);逸趣吉安麻将有挂吗软...