如何在 Android 14 中静默发送或更新通知

问题描述 投票:0回答:1

我最近将我的应用程序升级到 SDK v34 (Android 14),并遇到了通知问题。我发现 Android 14 不再支持 setOngoing(它仍然可以被滑动),而且,现在我的通知也不再静音。 setSound(null) 似乎也被忽略。它们每次都会振动或发出声音。这是我的通知生成器:

 String sChannelId = "notifyme_channel";
      NotificationCompat.Builder builder = new NotificationCompat.Builder(context, sChannelId)
              .setSmallIcon(iconResource)
              .setContentTitle(context.getString(R.string.app_name))
              .setContentText("Profile: " + AppInit.sCurActiveAlert + ", Alarm: " + AppInit.sNextAlarm)
              .setStyle(new NotificationCompat.BigTextStyle()
                      .bigText("Profile: " + AppInit.sCurActiveAlert + "\nNext Check: " +
                              AppInit.sNextScheduledProfileCheck + "\nNext Alarm: " + AppInit.sNextAlarm))
              .setTicker("Loading " + context.getString(R.string.app_name) + " notification...")
              .setWhen(System.currentTimeMillis())
              .setOngoing(true)
              .setSound(null)
              .setPriority(NotificationCompat.PRIORITY_DEFAULT);

通知横幅或图标不需要发出声音或振动,只是更新应用程序的状态,以便用户一目了然。

android notifications
1个回答
0
投票

哈哈

.setSilent(true).

我只是通过查看构建器参数才发现这一点并找到了 mSilent!不知道我是怎么错过这个的,但无论如何。

© www.soinside.com 2019 - 2024. All rights reserved.