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

相关推荐
与籍同行39 分钟前
安卓10.0 分屏相关
android
BD_Marathon1 小时前
Eclipse 代码自动补全设置
android·java·eclipse
w***74402 小时前
SQL Server 数据库迁移到 MySQL 的完整指南
android·数据库·mysql
zgyhc205010 小时前
【Android Audio】dumpsys media.metrics分析
android
nono牛10 小时前
Android Binder 详解与实践指南
android·binder
小镇学者11 小时前
【PHP】PHP WebShell(网页木马)分析
android·开发语言·php
2501_9160074712 小时前
iOS 压力测试的工程化体系,构建高强度、多维度、跨工具协同的真实负载测试流程
android·ios·小程序·uni-app·cocoa·压力测试·iphone
毕设源码-钟学长13 小时前
【开题答辩全过程】以 浮生馆汉服租赁管理系统为例,包含答辩的问题和答案
android·java·tomcat
louisgeek14 小时前
Android NDK 开发中的崩溃排查
android
2501_9159214315 小时前
iOS 开发者工具推荐,构建从调试到性能优化的多维度生产力工具链(2025 深度工程向)
android·ios·性能优化·小程序·uni-app·iphone·webview