【问题标题】:Notification custom layout does not work on Android 11通知自定义布局不适用于 Android 11
【发布时间】:2020-10-08 17:39:25
【问题描述】:

在我的 Android 应用中,我使用自定义布局的通知。 它从 Android 5 到 Android 10 都能完美运行。在 Android 11 中会出现一个通知,但它是空的。 我在代码中找不到任何问题。 有人可以帮帮我吗?

【问题讨论】:

  • 嗨@Podborovcan,欢迎来到 StackOverflow!你能否提供更多关于你实际在做什么的细节,比如你设置自定义通知的那段代码?

标签: android notifications


【解决方案1】:

我的一些代码行,但代码在 Android 5 到 Android 10 上都能完美运行,正如我所写的那样:

    private static NotificationCompat.Builder getBuilder(Context context){
        RemoteViews collapsedView = new RemoteViews(context.getPackageName(), R.layout.view_collapsed_notification);
        RemoteViews expandedView = new RemoteViews(context.getPackageName(), R.layout.view_expanded_notification_small);
        String channelId = NOTIFICATION_CHANNEL_ID;
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId);
        builder.setSmallIcon(R.drawable.ic_stat_heart_fill);
        builder.setStyle(new NotificationCompat.DecoratedCustomViewStyle());
        builder.setCustomContentView(collapsedView);
        builder.setCustomBigContentView(expandedView);
        return builder;
    }


    mNotificationManager.notify(NOTIFICATION_ID, getBuilder(context).build());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多