Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

targetSdk > 30时且使用后台更新模式,显示apk下载完成通知时会抛出异常 #170

Closed
StephenZKCurry opened this issue Oct 10, 2023 · 0 comments

Comments

@StephenZKCurry
Copy link

问题描述
targetSdk > 30时且使用后台更新模式,显示apk下载完成通知时会抛出异常,异常信息如下:
Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
原因是Android12的新特性,要求应用创建的每个PendingIntent对象都要指定可变性, 使用flag只能为PendingIntent.FLAG_MUTABLE 或PendingIntent.FLAG_IMMUTABLE,而在com.xuexiang.xupdate.service.DownloadService#showDownloadCompleteNotification()在创建PendingIntent时指定的flag是PendingIntent.FLAG_UPDATE_CURRENT。

使用的XUpdate版本(必填)
2.4.1

如何重现(必填)
1.项目的targetSdk > 30(31及以上)
2.设置supportBackgroundUpdate(true)
3.点击后台更新

期望的效果
建议创建PendingIntent时判断当前系统版本,根据不同系统版本创建带有不同flag的PendingIntent,如下:

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
    contentIntent = PendingIntent.getActivity(DownloadService.this, 0, installAppIntent, PendingIntent.FLAG_IMMUTABLE);
} else {
    contentIntent = PendingIntent.getActivity(DownloadService.this, 0, installAppIntent, PendingIntent.FLAG_UPDATE_CURRENT);
}

截图
异常信息
代码片段

设备信息

  • 设备名: Redmi K50
  • Android版本: Android 13
  • 设备型号 [e.g. ]:Redmi K50
  • 系统版本(手机厂商定制rom):MIUI 14.0.7
xuexiangjys added a commit that referenced this issue Mar 20, 2024
2.target sdk 提升至31
3.兼容Android12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants