android12适配中遇到的PendingIntent问题

2022-03-02 11:27:16.392 11813-11813/com.jia.decoration E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.jia.decoration, PID: 11813
    java.lang.IllegalArgumentException: com.jia.decoration: 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.getActivityAsUser(PendingIntent.java:458)
        at android.app.PendingIntent.getActivity(PendingIntent.java:444)
        at android.app.PendingIntent.getActivity(PendingIntent.java:408)
        at com.qijia.o2o.MainActivity$2.onClick(MainActivity.java:167)
        at android.view.View.performClick(View.java:7750)
        at android.view.View.performClickInternal(View.java:7727)
        at android.view.View.access$3700(View.java:861)
        at android.view.View$PerformClick.run(View.java:29133)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:210)
        at android.os.Looper.loop(Looper.java:299)
        at android.app.ActivityThread.main(ActivityThread.java:8085)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1045)

我最终是这么解决的:

//  implementation 'androidx.work:work-runtime:2.7.1'//java
    implementation 'androidx.work:work-runtime-ktx:2.7.1'//kotlin

还有使用的地方记得用

PendingIntent.FLAG_IMMUTABLE
  • 6
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值