Android PendingIntent 闪退

先来给大家推荐一个我日常会使用到的图片高清处理在线工具,主要是免费,直接白嫖 。

有时候我看到一张图片感觉很不错,但是图片清晰度不合我意,就想有没有什么工具可以处理让其更清晰,

网上随便搜下就能找到,但是搜出来的很大可能是需要付费,这里便发现了两个比较好用的值得推荐,

或许它每天对免费用户有一定的限制,但对于我每天可能也就处理不超过三张图片足矣,批量处理很可能还是付费吧!

这里对比可能不容易看出效果,最好实际操作。


PendingIntent 你可能不了解或者很少接触,当 targetSdk 31 >= 遇上 PendingIntent 一不小心就会崩溃 (ÒωÓױ)!

路人甲:我之前的代码也有使用 PendingIntent,运行好好地,没有你说的闪退 →_→

路人乙:这是非必现,还需要满足一些条件鸭

问题

java.lang.IllegalArgumentException: com.***.gamecenter:

Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.

解决

看堆栈就知道闪退是 androidx.work,他是什么?

在可运行模块 build.gradle 里强制依赖指定不闪退版本即可。

我一路尝试了好几个版本,从 2.0.0 ~ 2.8.0 发现 2.7.0 开始不闪退了,也就是此时开始 PendingIntent Flag 或许添加了 FLAG_IMMUTABLE or FLAG_MUTABLE 其中的某个或两个 flag。

java 复制代码
//	app/build.gradle
dependencies {
    //2.7.0   2.8.0
    //fix: argeting S+ (version " + Build.VERSION_CODES.S
    //370                      + " and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE"
    //371                      + " be specified when creating a PendingIntent.\nStrongly consider"
    //372                      + " using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality"
    //373                      + " depends on the PendingIntent being mutable, e.g. if it needs to"
    //374                      + " be used with inline replies or bubbles.
    configurations.all{
        resolutionStrategy.force 'androidx.work:work-runtime:2.7.0'
    }
}

设置了 targetSdk 31 同时它也要求 minCompileSdk 31,打包时记得更改就好了~

Tip:

如果你没有使用 androidx.work;

如果你已经使用了正确版本的 androidx.work;

如果你使用的 targetSdk 小于 31;

如果你没有使用 PendingIntent 那可能就没有这个问题啦!

如果你使用了,那可以检查 PendingIntent 和 targetSdk 是否可能存在这个问题。

相关推荐
c***21295 小时前
Springboot3学习(5、Druid使用及配置)
android·学习
修炼者5 小时前
【Android 进阶】别再强转 Context 了!手把手教你优雅解耦 View 与 Activity
android·android studio
x***01065 小时前
SpringSecurity+jwt实现权限认证功能
android·前端·后端
程序员江同学6 小时前
线下活动|2025 Kotlin 中文开发者大会北京分会场
android·kotlin
李坤林7 小时前
Android Vulkan 开启VK_GOOGLE_DISPLAY_TIMING 后,一个vsync 会释放两个imageBuffer现象分析
android·vulkan
Jerry7 小时前
Compose 状态思维
android
k***45997 小时前
MySQL----case的用法
android·数据库·mysql
r***86989 小时前
Plugin ‘mysql_native_password‘ is not loaded`
android·数据库·mysql
v***59839 小时前
MySQL-mysql zip安装包配置教程
android·mysql·adb
不用89k9 小时前
Android无法区分USB摄像头是哪一个
android