Cordova Android应用:如何指定PendingIntent的mutability属性以解决崩溃?
问题:Cordova Android应用在Android 13启动位置追踪时崩溃
- 应用基于Cordova开发,目标Android SDK版本为31,集成了位置追踪插件
- Android 11及以下版本运行完全正常,但在Android 13设备上,仅启动位置追踪时会崩溃
崩溃日志详情
java.lang.RuntimeException: Unable to start service com.marianhello.bgloc.LocationService@705152b with Intent { flg=0x4 cmp=com. myapp.com/com.marianhello.bgloc.LocationService (has extras) }: java.lang.IllegalArgumentException: com. myapp.com: 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. at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4846) at android.app.ActivityThread.access$2200(ActivityThread.java:275) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2223) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:211) at android.os.Looper.loop(Looper.java:300) at android.app.ActivityThread.main(ActivityThread.java:8301) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:577) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076) Caused by: java.lang.IllegalArgumentException: com. myapp.com: 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. at android.app.PendingIntent.checkFlags(PendingIntent.java:375) at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645) at android.app.PendingIntent.getBroadcast(PendingIntent.java:632) at com.marianhello.bgloc.ActivityRecognitionLocationProvider.onCreate(ActivityRecognitionLocationProvider.java:60) at com.marianhello.bgloc.LocationProviderFactory.getInstance(LocationProviderFactory.java:43) at com.marianhello.bgloc.LocationService.onStartCommand(LocationService.java:239) at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4828) ... 9 more
- 已尝试多个平台提供的解决方案,但均未奏效
- 遇到的问题与Stack Overflow上某用户类似,但该问题的解答不适用
内容的提问来源于stack exchange,提问作者Balty
相关产品推荐
相关产品推荐

