Android 14前台通知无法正常更新:SDK34升级后的优先级两难问题
Android 14(SDK 34)前台通知布局无法更新,仅高优先级渠道可行但会弹窗
问题描述
近期将应用SDK版本升级至34,在Android 14设备测试时发现:前台通知布局无法正常更新,除非将通知渠道优先级设为IMPORTANCE_HIGH,但这会触发不必要的弹窗。
代码片段
private void setup() { setupIndicatorIconGenerator(); String channel = createChannel(); NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext, channel) .setSmallIcon(getIndicatorIcon("", "")) .setPriority(NotificationCompat.PRIORITY_HIGH) .setContent(mNotificationContentView) .setOngoing(true) .setSound(null) .setVibrate(new long[] {0}) .setCategory(NotificationCompat.CATEGORY_SERVICE) .setShowWhen(false) .setLocalOnly(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { builder.setForegroundServiceBehavior(NotificationCompat.FOREGROUND_SERVICE_IMMEDIATE); } mNotificationBuilder = builder; } private synchronized String createChannel() { if (mContext == null) { // Handle the case where mContext is null return null; } this.mNotificationManager = mContext.getSystemService(NotificationManager.class); if (mNotificationManager == null) { // Handle the case where mNotificationManager is null return null; } String channelId = "id_channel"; String channelName = "name"; int importance = NotificationManager.IMPORTANCE_HIGH; if(Build.VERSION.SDK_INT >= 26){ NotificationChannel mChannel = new NotificationChannel(channelId, channelName, importance); mChannel.setVibrationPattern(new long[]{0}); mChannel.enableVibration(false); mChannel.setSound(null, null); mChannel.setDescription("Description "); mChannel.setBypassDnd(true); mNotificationManager.createNotificationChannel(mChannel); }else{ channelId = ""; } return channelId; }
已尝试的方案
- 调整通知渠道优先级至非高等级,此时通知布局无法正常更新
- 测试不同的前台服务行为参数,未找到有效解决办法
环境信息
- SDK版本:34
- Android版本:14
期望目标
将通知渠道优先级设为非高等级时,通知布局仍能正常更新且不会触发弹窗。
内容的提问来源于stack exchange,提问作者Mohammad Azizi
相关产品推荐
相关产品推荐

