即使在同一台设备上,通知操作按钮也不一致 UI

Inconsistent notification actions buttons' UI even on same device

我有一个应用程序,我遇到了一些问题,即通知在不同设备上不一致。通知由前台服务使用

这是我的通知在我的 pixel3 api29 模拟器中的样子

由于我正在解决的问题,我决定提取代码并将其放入一个虚拟应用程序中,这样我就可以更轻松地模拟触发事件。然而,在完全相同的 pixel3 api29 模拟器上这样做和 运行 之后,我意识到通知甚至不一致 在同一设备上 。在虚拟前台服务的虚拟应用程序中,通知如下所示

我找不到导致这两个应用中操作按钮外观不同的原因。甚至行为也不同。在第一个版本中,浮动提醒通知会一直存在,直到我以编程方式清除它,但在第二个虚拟应用程序中,通知会在 6 秒后自行清除。我尝试在两者中使用相同的主题,添加了完全相同的依赖版本,认为我正在拉取不同版本的通知库但没有,创建通知的代码在两者中是相同的:

    private Notification createIncomingCallNotification(Intent intent) {
        Intent hangupIntent = new Intent(this, getClass());
        hangupIntent.setAction("hangup");
        PendingIntent hangupPendingIntent = PendingIntent.getService(this, 1244, hangupIntent, PendingIntent.FLAG_ONE_SHOT);
        NotificationCompat.Action hangupAction = new NotificationCompat.Action.Builder(0, getActionText(R.string.hangup_button_label, R.color.test1), hangupPendingIntent).build();

        Intent uiIntent = new Intent(this, VideoCallActivity.class);
        uiIntent.putExtras(intent);
        uiIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(this, 0, uiIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        NotificationCompat.Action previewAction = new NotificationCompat.Action.Builder(0, getActionText(R.string.preview, R.color.test2), fullScreenPendingIntent).build();

        String caller = "Caller guy";
        Log.v(TAG, "Creating incoming call notification from " + caller);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, ChannelIds.INCOMING_CALL_CHANNEL_ID)
                .setContentTitle(getString(R.string.incoming_call_notification_title, caller))
                .setPriority(NotificationCompat.PRIORITY_MAX)
                .setCategory(NotificationCompat.CATEGORY_CALL)
                .setSmallIcon(R.drawable.ic_white_100dp)
                .addAction(hangupAction)
                .addAction(previewAction)
                .setOnlyAlertOnce(true)
                .setFullScreenIntent(fullScreenPendingIntent, true);

        return notificationBuilder.build();
    }

    private Spanned getActionText(@StringRes int stringRes, @ColorRes int colourRes) {
        Spannable spannable = new SpannableString(getText(stringRes));
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
            // This will only work for cases where the Notification.Builder has a fullscreen intent set
            // Notification.Builder that does not have a full screen intent will take the color of the
            // app and the following leads to a no-op.
            spannable.setSpan(new ForegroundColorSpan(getColor(colourRes)), 0, spannable.length(), 0);
        }
        return spannable;
    }

有谁知道即使在同一台设备上也会导致这种不一致的原因?

我终于明白了。改变抬头通知的是清单中的这个权限

<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT"/>