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

相关内容

热门资讯

第二分钟辅助!wepoker怎... 第二分钟辅助!wepoker怎么开辅助,wpk作弊是真的吗,指引教程(有挂工具)1、这是跨平台的we...
十分钟辅助!wepoker辅助... 十分钟辅助!wepoker辅助器软件下载,wepoker透视版下载,秘籍教程(发现有挂)1、打开软件...
第九分钟辅助!wepoker游... 第九分钟辅助!wepoker游戏安装教程,aapoker脚本,手筋教程(真的有挂)1、进入游戏-大厅...
第六分钟辅助!wpk透视是真的... 第六分钟辅助!wpk透视是真的假的,xpoker怎么作弊,阶段教程(有挂分析)1、进入游戏-大厅左侧...
5分钟辅助!大菠萝辅助器,im... 5分钟辅助!大菠萝辅助器,impoker辅助,操作教程(有挂透明挂)1、上手简单,内置详细流程视频教...
2分钟辅助!aapoker能控... 您好,aapoker能控制牌吗这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302...
第1分钟辅助!WePOker有... 第1分钟辅助!WePOker有没有透视方法,aapoker怎么选牌,指引教程(有挂解密)1、WePO...
第九分钟辅助!wepoker透... 第九分钟辅助!wepoker透视脚本网页,如何下载wepoker安装包,技法教程(有挂方法)一、如何...
第八分钟辅助!wepoker安... 第八分钟辅助!wepoker安装教程,pokernow辅助控制,总结教程(有挂方略)在进入poker...
第八分钟辅助!德州机器人代打脚... 第八分钟辅助!德州机器人代打脚本,xpoker辅助助手,总结教程(有挂方略)德州机器人代打脚本透视方...