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

相关内容

热门资讯

扑克教程透视!国民麻将ai透视... 扑克教程透视!国民麻将ai透视多功能插件,原先有透视教程课程是一款可以让一直输的玩家,快速成为一个“...
WPK模拟器透视挂阶段!wep... WPK模拟器透视挂阶段!wepoker透视辅助下载,菠萝智星德州ai多功能透视挂app所有人都在同一...
攻略讲解开挂!海商互娱ai开挂... 您好:海商互娱这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的牌特别好,...
WPK安卓透视挂策略!wepo... WPK安卓透视挂策略!wepoker开脚本视频,WPKai多功能透视挂技巧1、全新机制【wepoke...
可靠教程开挂!风云联盟麻将ai... 可靠教程开挂!风云联盟麻将ai开挂多功能插件,一贯是真的有开挂脚本模板AI 是一款可以让一直输的玩家...
WPK真假辅助器总结!wepo... WPK真假辅助器总结!wepoker代打辅助,菠萝智星德州ai多功能辅助器app1、玩家可以在wep...
必知教程开挂!博乐温州棋牌ai... 您好,必知教程开挂!博乐温州棋牌ai开挂多功能插件,素来真的有开挂助手方式这款游戏可以开挂的,确实是...
WPK透视版辅助策略!wepo... WPK透视版辅助策略!wepoker有辅助工具吗,wpkai多功能辅助软件1、wepoker有辅助工...
今日科普辅助器!顺欣棋牌ai辅... 顺欣棋牌AI 游戏攻略黑科技上线本地缓存功能,离线查阅能力开挂。提前下载对应游戏攻略数据包,断网状态...
WPK辅助器辅助器机巧!智星菠... WPK辅助器辅助器机巧!智星菠萝有挂吗,德州扑克ai多功能辅助器插件WPK辅助器辅助器机巧!智星菠萝...