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

相关推荐
踢球的打工仔2 小时前
PHP面向对象(7)
android·开发语言·php
安卓理事人2 小时前
安卓socket
android
安卓理事人8 小时前
安卓LinkedBlockingQueue消息队列
android
万能的小裴同学9 小时前
Android M3U8视频播放器
android·音视频
q***57749 小时前
MySql的慢查询(慢日志)
android·mysql·adb
JavaNoober10 小时前
Android 前台服务 "Bad Notification" 崩溃机制分析文档
android
城东米粉儿10 小时前
关于ObjectAnimator
android
zhangphil11 小时前
Android渲染线程Render Thread的RenderNode与DisplayList,引用Bitmap及Open GL纹理上传GPU
android
火柴就是我12 小时前
从头写一个自己的app
android·前端·flutter
lichong95113 小时前
XLog debug 开启打印日志,release 关闭打印日志
android·java·前端