开发者社区 问答 正文

应用研发平台EMAS中Android 端最新依赖版本线上遇到的 Crash, 有更新的版本吗?

应用研发平台EMAS中Android 端最新依赖版本,target 31 crash,线上遇到的 Crash, 有更新的版本吗java.lang.IllegalArgumentException: com.kfm.android.mobile: 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.a9c9d51cdadbf85d382ef03793921d0f.png

展开
收起
小小鹿鹿鹿 2023-09-18 14:33:02 124 分享 版权
1 条回答
写回答
取消 提交回答
  • 这个问题是因为在Android 12及更高版本中,PendingIntent的一个新特性导致的。当你创建一个PendingIntent时,你需要指定FLAG_IMMUTABLE或FLAG_MUTABLE标志。这是因为在新的Android版本中,PendingIntent是不可变的,除非你明确地指定了一个可变的标志。

    对于这个问题,你可以尝试在你的代码中使用以下代码来解决:

    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, requestCode, intent, PendingIntent.FLAG_IMMUTABLE);
    

    在这个例子中,我们使用FLAG_IMMUTABLE标志来创建一个不可变的PendingIntent。这样,即使应用程序的目标是S+(版本31及以上),也不会出现Crash。

    2023-09-21 11:49:37
    赞同 展开评论