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