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

相关内容

热门资讯

一分钟揭秘,wepokerpl... 本地部署 AI 黑科技工具迎来新版本,不用上传文件到云端就能完成wepokerplus挂先试用后付款...
交流学习经验,wepoker好... 您好,交流学习经验,wepoker好牌率,AApoker透视脚本教材(从前有开挂)这款游戏可以开挂的...
总算了解!,AApoker的破... 您好:AApoker的破解方法这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多...
玩家攻略,wepoker开挂辅... 玩家攻略,wepoker开挂辅助方法,wpk确实有挂妙招(好像是真的有透视)是一款可以让一直输的玩家...
指导大家,德州ai辅助辅助工具... 指导大家,德州ai辅助辅助工具购买,aapoker有没有辅助插件教材(本来真的有辅助挂)是一款可以让...
必备教程,德州wpk透视辅助器... 德州wpk透视辅助器最新版本更新内容AI 游戏攻略黑科技上线本地缓存功能,离线查阅能力开挂。提前下载...
分享一款,德州如何看牌面技巧,... AI 黑科技赛道又上新,这款智能处理工具堪称效率开挂,专门面向短视频创作者打造。它打通脚本撰写、AI...
记者揭秘!,wepoker透视... 记者揭秘!,wepoker透视软件下载,智星菠萝德州开挂脚本项目(最初有透视挂)是一款可以让一直输的...
技巧知识分享,wepoker原... 技巧知识分享,wepoker原来有挂,微扑克透视神器方针(切实是有开挂)是一款可以让一直输的玩家,快...
2025版教程,aapoker... 您好,2025版教程,aapoker透视辅助下载,德州扑克有没有挂吗攻略(确实真的有辅助挂)这款游戏...