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

相关推荐
_李小白6 小时前
【Android FrameWork】第二十四天:Activity生命周期是如何运行的
android
ytttr8737 小时前
基于C#的CAN总线数据解析BMS上位机
android·unity·c#
darryrzhong8 小时前
FluxImageLoader : 基于Coil3封装的 Android 图片加载库,旨在提供简单、高效且功能丰富的图片加载解决方案
android·github·android jetpack
pandarking8 小时前
[CTF]攻防世界:题目名称-warmup
android·web安全·网络安全
我命由我123458 小时前
Android 开发问题:在无法直接获取或者通过传递获取 Context 的地方如何获取 Context
android·java·java-ee·android studio·android jetpack·android-studio·android runtime
惟恋惜9 小时前
Jetpack Compose之“副作用”的讲解
android
モンキー・D・小菜鸡儿10 小时前
Android14 新特性与适配指南
android·kotlin·安卓新特性
技术摆渡人10 小时前
Android系统技术探索(1)启动流程
android
介一安全13 小时前
【Frida Android】实战篇12:企业常用对称加密场景 Hook 教程
android·网络安全·逆向·安全性测试·frida
モンキー・D・小菜鸡儿13 小时前
Android15 新特性与适配指南
android·kotlin·安卓新特性