【已解决】Android12以上PendingIntent需要强制增加FLAG_IMMUTABLE或FLAG_MUTABLE
短信预约 -IT技能 免费直播动态提醒
Android13适配时报下面错误:
java.lang.IllegalArgumentException: android: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
02-26 20:00:47.055 27821 27821 I System : java.lang.IllegalArgumentException: android: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.02-26 20:00:47.055 27821 27821 I System : 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.02-26 20:00:47.055 27821 27821 I System : at android.app.PendingIntent.checkFlags(PendingIntent.java:404)02-26 20:00:47.055 27821 27821 I System : at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:674)02-26 20:00:47.055 27821 27821 I System : at android.app.PendingIntent.getBroadcast(PendingIntent.java:661)02-26 20:00:47.055 27821 27821 I System : at com.XX.server.ntp.SunmiNetworkTimeUpdateService.(SunmiNetworkTimeUpdateService.java:148)02-26 20:00:47.055 27821 27821 I System : at com.XX.server.SunmiSystemServer.(SunmiSystemServer.java:55)02-26 20:00:47.055 27821 27821 I System : at com.android.server.SystemServer.startOtherServices(SystemServer.java:2414)02-26 20:00:47.055 27821 27821 I System : at com.android.server.SystemServer.run(SystemServer.java:944)02-26 20:00:47.055 27821 27821 I System : at com.android.server.SystemServer.main(SystemServer.java:654)02-26 20:00:47.055 27821 27821 I System : at java.lang.reflect.Method.invoke(Native Method)02-26 20:00:47.055 27821 27821 I System : at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)02-26 20:00:47.055 27821 27821 I System : at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:920)02-26 20:00:47.055 27821 27821 W SystemServer: ***********************************************02-26 20:00:47.055 27821 27821 E SystemServer: BOOT FAILURE starting SunmiSystemServer02-26 20:00:47.055 27821 27821 E SystemServer: java.lang.IllegalArgumentException: android: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.02-26 20:00:47.055 27821 27821 E SystemServer: 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.02-26 20:00:47.055 27821 27821 E SystemServer: at android.app.PendingIntent.checkFlags(PendingIntent.java:404)02-26 20:00:47.055 27821 27821 E SystemServer: at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:674)02-26 20:00:47.055 27821 27821 E SystemServer: at android.app.PendingIntent.getBroadcast(PendingIntent.java:661)02-26 20:00:47.055 27821 27821 E SystemServer: at com.XX.server.ntp.SunmiNetworkTimeUpdateService.(SunmiNetworkTimeUpdateService.java:148)02-26 20:00:47.055 27821 27821 E SystemServer: at com.XX.server.SunmiSystemServer.(SunmiSystemServer.java:55)02-26 20:00:47.055 27821 27821 E SystemServer: at com.android.server.SystemServer.startOtherServices(SystemServer.java:2414)02-26 20:00:47.055 27821 27821 E SystemServer: at com.android.server.SystemServer.run(SystemServer.java:944)02-26 20:00:47.055 27821 27821 E SystemServer: at com.android.server.SystemServer.main(SystemServer.java:654)02-26 20:00:47.055 27821 27821 E SystemServer: at java.lang.reflect.Method.invoke(Native Method)02-26 20:00:47.055 27821 27821 E SystemServer: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)02-26 20:00:47.055 27821 27821 E SystemServer: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:920)02-26 20:00:47.056 27821 27821 D SystemServerTiming: StartPrintManager
修改方法:
148 if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) { 149 mPendingPollIntent = PendingIntent.getBroadcast(mContext, POLL_REQUEST, pollIntent, PendingIntent.FLAG_IMMUTABLE); 150 }else{ 151 mPendingPollIntent = PendingIntent.getBroadcast(mContext, POLL_REQUEST, pollIntent, 0); 152 }
参考:
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341