Vintage appMaker의 Tech Blog

[Android 12] Pending Intent 적용정책 본문

Source code or Tip/Android(Java, Kotlin)

[Android 12] Pending Intent 적용정책

VintageappMaker 2022. 4. 4. 11:25

2022-04-04 20:09:18.803 5256-5256/com.psw.batteryToast E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.psw.batteryToast, PID: 5256
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.psw.batteryToast/com.psw.batteryToast.MainActivity}: java.lang.IllegalArgumentException: com.psw.batteryToast: 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.performLaunchActivity(ActivityThread.java:3635)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3792)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2210)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7839)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
     Caused by: java.lang.IllegalArgumentException: com.psw.batteryToast: 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.psw.batteryToast.MainActivity.onCreate(MainActivity.kt:85)
        at android.app.Activity.performCreate(Activity.java:8051)
        at android.app.Activity.performCreate(Activity.java:8031)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3608)
            ... 12 more

Android SDK 31 이상을 사용할 경우,
Pending Intent 파라메터로 FLAG_IMMUTABLE 을 강권하고 있다.

 

예외가 있긴하지만 대부분 그렇게 해야 한다.

Android SDK 31이하에서는 문제가 없지만, Google Play에서 받아주지 않는다.
그러므로 마켓 업로드하려면 위의 코드는 반드시 적용되어야 한다.

 

 

 

Battery history - Google Play 앱

배터리가 소모된 기록을 저장, 관리해주는 앱

play.google.com

 

Comments