【问题标题】:FLAG_IMMUTABLE causing error in android 31FLAG_IMMUTABLE 在 android 31 中导致错误
【发布时间】:2023-02-22 20:08:30
【问题描述】:

这里只有一个地方使用了 PendingIntent,即使在那里添加了 FLAG_IMMUTABLE 之后也是如此。我收到错误。

implementation 'androidx.work:work-runtime:2.7.1'

在 build.gradle 中添加了上述行,仍然出现此错误。可以请任何人提供有关它的见解。

【问题讨论】:

标签: android android-studio


【解决方案1】:

目前我的一个项目发生这种情况先生请分享你的代码为了更好地理解 虽然我正在做一个假设你的代码是什么 试试这个因为 SDK 版本更改我们需要用 SDK 版本的条件包围

这是帮助我摆脱这个错误的源代码

PendingIntent pendingIntent;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
        pendingIntent = PendingIntent.getActivity(this,
                0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);

    }else {
        pendingIntent = PendingIntent.getActivity(this,
                0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    }
//        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, 
intent, PendingIntent.FLAG_UPDATE_CURRENT);
    showNotification(title, body, badge, pendingIntent);

【讨论】:

    猜你喜欢
    • 2022-01-20
    • 2022-12-14
    • 2014-11-29
    • 2021-04-11
    • 1970-01-01
    • 2020-02-24
    • 2013-11-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多