Android13中通知不显示下一页和上一页按钮
创始人
2024-10-01 11:30:16
0

在Android 13中,通知的下一页和上一页按钮已被隐藏。要显示这些按钮,需要添加以下代码:

if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.S){
      Notification.BubbleMetadata bubbleMetadata = null;
      Notification.Builder builder = new Notification.Builder(context, channelId)
                  .setContentTitle(title)
                  .setContentText(content)
                  .setSmallIcon(R.drawable.ic_launcher_foreground)
                  .setBubbleMetadata(bubbleMetadata);

      Notification.Action prevAction = new Notification.Action.Builder(
          Icon.createWithResource(context, R.drawable.ic_previous),
          "Previous",
          prevPendingIntent
      ).build();

      Notification.Action nextAction = new Notification.Action.Builder(
          Icon.createWithResource(context, R.drawable.ic_next),
          "Next",
          nextPendingIntent
      ).build();

      builder.addAction(prevAction);
      builder.addAction(nextAction);

      notificationManager.notify(notificationId, builder.build());
  }
  else {
      NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId)
                  .setContentTitle(title)
                  .setContentText(content)
                  .setSmallIcon(R.drawable.ic_launcher_foreground);

      NotificationCompat.Action prevAction = new NotificationCompat.Action.Builder(
          R.drawable.ic_previous,
          "Previous",
          prevPendingIntent
      ).build();

      NotificationCompat.Action nextAction = new NotificationCompat.Action.Builder(
          R.drawable.ic_next,
          "Next",
          nextPendingIntent
      ).build();

      builder.addAction(prevAction);
      builder.addAction(nextAction);

      notificationManager.notify(notificationId, builder.build());
  }

上面的代码进行了检查,如果设备API级别为Android 13或更高级别,则使用Notification.BubbleMetadataNotification.Action.Builder添加下一页和上一页按钮。否则,使用NotificationCompat.Action.Builder添加按钮。

值得注意的是,添加下一页和上一页按钮将使通知显示为气泡。如果您不想要气泡,可以将Notification.BubbleMetadatasetBubbleMetadata()删除,并将builder替换为NotificationCompat.Builder

相关内容

热门资讯

2分钟辅助!创思维激k有挂吗,... 【亲,创思维激k有挂吗 这款游戏可以开挂的,确实是有挂的,很多玩家在这款创思维激k有挂吗中打牌都会发...
第十分钟辅助!wepoker亲... 第十分钟辅助!wepoker亲友圈有用吗,丹东约战麻将辅助器(一分钟了解开挂辅助脚本);亲真的是有正...
6分钟开挂!wepoker透视... 6分钟开挂!wepoker透视脚本下载,闲逸辅助脚本(透视透视开挂辅助神器);无需打开直接搜索微信(...
5分钟辅助!皮皮胡子辅助,潮友... 5分钟辅助!皮皮胡子辅助,潮友会虾蟹骰子概率计算方式(玩家必看开挂辅助安装);潮友会虾蟹骰子概率计算...
1分钟辅助!微信微乐有挂没有,... 1分钟辅助!微信微乐有挂没有,微信中至有辅助吗(透视有挂开挂辅助平台);相信小伙伴都知道这个微信中至...
第1分钟辅助!禅游游戏辅助,乐... 第1分钟辅助!禅游游戏辅助,乐平包王攻略(科普常识开挂辅助平台);大家肯定在之前乐平包王攻略或者乐平...
第9分钟开挂!广西微乐小程序脚... 第9分钟开挂!广西微乐小程序脚本,河洛杠次插件(最新技巧开挂辅助下载)【无需打开直接搜索加薇1367...
第4分钟辅助!贪玩互娱辅助,微... 第4分钟辅助!贪玩互娱辅助,微乐小程序挂哪里有(今日重大通报开挂辅助工具);相信小伙伴都知道这个微乐...
第七分钟开挂!欢聚水鱼天下辅助... 您好:这款欢聚水鱼天下辅助游戏是可以开挂的,确实是有挂的,很多玩家在这款欢聚水鱼天下辅助游戏中打牌都...
第四分钟辅助!xpoker透视... 第四分钟辅助!xpoker透视辅助,小闲川南手游辅助器(技巧知识分享开挂辅助安装);小薇(透视辅助)...