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控制牌!aapoker工... WPK控制牌!aapoker工具辅助器ai,wpk系统是否存在作弊行为,其实是有ai辅助器烘培1、任...
WPK辅助器!菠萝智星德州ap... WPK辅助器!菠萝智星德州app透视挂ai,微扑克游戏辅助器,真是真的是有ai透视挂操作1、游戏颠覆...
WPK脚本!德州扑克方法辅助a... 您好,哈糖大菠萝挂这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家在...
WPK俱乐部!WePoKer攻... WPK俱乐部!WePoKer攻略开挂ai,werplan外挂,总是有ai开挂手段1、WPK俱乐部!W...
WPK购买!红龙扑克教程开挂a... WPK购买!红龙扑克教程开挂ai,哈糖大菠萝有挂吗5个常用方法,好像存在有ai开挂教材运哈糖大菠萝有...
WPK购买!微扑克教程透视ai... WPK购买!微扑克教程透视ai,AApoker辅助插件,总是有ai透视模块1、完成AApoker辅助...
WPK模拟器!菠萝智星德州工具... WPK模拟器!菠萝智星德州工具透视ai,AApoker中牌率,真是真的是有ai透视指南AApoker...
WPK多开!菠萝智星德州技巧开... WPK多开!菠萝智星德州技巧开挂ai,AApoker好牌,一直真的是有ai开挂课程暗藏猫腻,小编详细...
WPK靠谱!菠萝智星德州技巧辅... WPK靠谱!菠萝智星德州技巧辅助ai,werplan外卦神器,一直存在有ai辅助经验1、玩家可以在w...
WPK安装!WePoKer插件... WPK安装!WePoKer插件辅助器ai,佛手在线有挂吗,真是真的有ai辅助器要领1、进入到佛手在线...