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 是否可能存在这个问题。

相关推荐
Dingdangr3 小时前
Android中的Intent的作用
android
技术无疆3 小时前
快速开发与维护:探索 AndroidAnnotations
android·java·android studio·android-studio·androidx·代码注入
GEEKVIP3 小时前
Android 恢复挑战和解决方案:如何从 Android 设备恢复删除的文件
android·笔记·安全·macos·智能手机·电脑·笔记本电脑
Jouzzy10 小时前
【Android安全】Ubuntu 16.04安装GDB和GEF
android·ubuntu·gdb
极客先躯10 小时前
java和kotlin 可以同时运行吗
android·java·开发语言·kotlin·同时运行
Good_tea_h13 小时前
Android中的单例模式
android·单例模式
计算机源码社18 小时前
分享一个基于微信小程序的居家养老服务小程序 养老服务预约安卓app uniapp(源码、调试、LW、开题、PPT)
android·微信小程序·uni-app·毕业设计项目·毕业设计源码·计算机课程设计·计算机毕业设计开题
丶白泽18 小时前
重修设计模式-结构型-门面模式
android
晨春计20 小时前
【git】
android·linux·git
标标大人21 小时前
c语言中的局部跳转以及全局跳转
android·c语言·开发语言