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

相关内容

热门资讯

黑科技辅助!pokerist有... 黑科技辅助!pokerist有挂(德扑ai智能机器人)果然是有挂(有挂详情)-哔哩哔哩1、任何德州a...
黑科技好友房!aapoker透... 黑科技好友房!aapoker透明挂(wpk ai辅助)素来是真的有挂(有挂教学)-哔哩哔哩1、超多福...
黑科技存在!gg扑克可以赢不了... 黑科技存在!gg扑克可以赢不了(微扑克透牌)一贯是有挂(有挂详情)-哔哩哔哩1、微扑克透牌系统规律教...
黑科技能赢!wepoke计算辅... 黑科技能赢!wepoke计算辅助(wepoke黑科技)往昔是真的有挂(揭秘有挂)-哔哩哔哩是一款可以...
黑科技辅助挂!wepoke a... 黑科技辅助挂!wepoke ai辅助(微扑克如何让系统发好牌)一向是有挂(发现有挂)-哔哩哔哩;小薇...
黑科技了解!德州ai辅助器(微... 黑科技了解!德州ai辅助器(微扑克ai机器人)最初是有挂(有挂解密)-哔哩哔哩1、实时微扑克ai机器...
黑科技脚本!wepoke用模拟... 黑科技脚本!wepoke用模拟器(德扑ai机器人软件开发)原先是真的有挂(有挂神器)-哔哩哔哩1、德...
黑科技脚本!德州ai辅助神器软... 黑科技脚本!德州ai辅助神器软件(aa poker有外挂吗)一贯真的是有挂(果真有挂)-哔哩哔哩1、...
黑科技玄学!约局吧发牌逻辑(w... 1、黑科技玄学!约局吧发牌逻辑(wepoke辅助插件)总是存在有挂(确实有挂)-哔哩哔哩;代表性(透...
黑科技攻略!aapoker透明... 黑科技攻略!aapoker透明(aapoker真的有猫腻吗)从前是真的有挂(有挂教程)-哔哩哔哩;a...