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相匹配。

相关内容

热门资讯

WPK私人局辅助器项目!wep... WPK私人局辅助器项目!wepoker破解是真的还是假的,德州扑克ai多功能辅助器技巧wepoker...
2027版透视挂!西元红河棋牌... 2027版透视挂!西元红河棋牌透视挂多功能AI插件,西元红河棋牌好像真的有透视挂插件1、起透看视 西...
揭秘关于辅助挂!tx同城棋牌麻... 一款 AI 游戏攻略黑科技工具上线,查攻略效率直接开挂。它整合版本更新、装备搭配、BOSS 打法、牌...
WPK作弊开挂指南!wepok... WPK作弊开挂指南!wepoker怎么开辅助,红龙扑克ai多功能开挂app1、该软件可以轻松地帮助玩...
2027版辅助器!喜乐麻将辅助... 2027版辅助器!喜乐麻将辅助器多功能AI工具,喜乐麻将原来是有辅助器工具1、喜乐麻将透视辅助软件激...
一起来讨论辅助!土豪老友麻将a... 土豪老友麻将AI 游戏攻略黑科技上线本地缓存功能,离线查阅能力开挂。提前下载对应游戏攻略数据包,断网...
WPK购买开挂窍门!wepok... 您好,wepoker私人局辅助器怎么用这款游戏可以开挂的,确实是有挂的,需要了解加去威信【13670...
2027版辅助器!胡乐阳泉麻将... 2027版辅助器!胡乐阳泉麻将辅助器多功能AI攻略,胡乐阳泉麻将确实真的是有辅助器攻略所有人都在同一...
免费测试版透视!科乐麻将ai透... 免费测试版透视!科乐麻将ai透视多功能插件,原来真的是有透视助手窍门主打赛后复盘的 AI 游戏攻略黑...
WPK工具辅助器手册!wepo... WPK工具辅助器手册!wepoker辅助器怎么弄,德州扑克ai多功能辅助器软件wepoker辅助器怎...