当针对S+(版本31及以上)进行定位时,需要在创建PendingIntent时指定FLAG_IMMUTABLE或FLAG_MUTABLE之一。

4

我使用 Kotlin 语言。

我一直遇到这个待处理意图错误。

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.chugnchunon.chungchunon_android, PID: 20394
    java.lang.RuntimeException: Unable to create application com.chugnchunon.chungchunon_android.GlobalApplication: java.lang.IllegalArgumentException: com.chugnchunon.chungchunon_android: 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.handleBindApplication(ActivityThread.java:6764)
        at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2133)
        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:7872)
        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:936)
     Caused by: java.lang.IllegalArgumentException: com.chugnchunon.chungchunon_android: 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:401)
        at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:671)
        at android.app.PendingIntent.getBroadcast(PendingIntent.java:658)
        at com.kakao.auth.Session.<init>(Session.java:156)
        at com.kakao.auth.Session.initialize(Session.java:101)
        at com.kakao.auth.KakaoSDK.init(KakaoSDK.java:101)
        at com.chugnchunon.chungchunon_android.GlobalApplication.onCreate(GlobalApplication.kt:17)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1277)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6759)
            ... 9 more

但是当我在我的项目中搜索挂起意图时,我根本没有使用PendingIntent

这个错误提到了GlobalApplication.kt:17

在GlobalApplication中:

包名为com.chugnchunon.chungchunon_android。

import android.app.Application
import com.chugnchunon.chungchunon_android.Adapter.KakaoSDKAdapter
import com.kakao.auth.*

class GlobalApplication : Application() {
    companion object {
        var instance: GlobalApplication? = null
    }

    override fun onCreate() {
        super.onCreate()
        instance = this

        KakaoSDK.init(KakaoSDKAdapter(getAppContext()))
    }

    override fun onTerminate() {
        super.onTerminate()
        instance = null
    }

    fun getAppContext(): GlobalApplication {
        checkNotNull(instance) {
            "This Application does not inherit com.example.App"
        }
        return instance!!
    }
}

没有PendingIntent。

有些人建议在build.gradle(:app)中设置以下依赖项。

implementation 'androidx.work:work-runtime-ktx:2.7.0'

我做了这件事,但仍然遇到了错误。

我该如何解决它?

2个回答

5
我试图运行前台服务并遇到了类似的问题。 我使用PendingIntent 来通知用户有关前台服务的信息。 我将标志值从0更改为最后一个参数中的PendingIntent.FLAG_IMMUTABLE,在我的情况下得到了解决。
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 1, intent, 0);

使用这个替代

PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 1, intent, PendingIntent.FLAG_IMMUTABLE);

我希望这个答案能够帮到你


我没有使用PendingIntent,但仍然遇到了这个问题。 - chanrlc

0
     Caused by: java.lang.IllegalArgumentException: com.chugnchunon.chungchunon_android: 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:401)
        at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:671)
        at android.app.PendingIntent.getBroadcast(PendingIntent.java:658)
        at com.kakao.auth.Session.<init>(Session.java:156)
        at com.kakao.auth.Session.initialize(Session.java:101)
        at com.kakao.auth.KakaoSDK.init(KakaoSDK.java:101)
        at com.chugnchunon.chungchunon_android.GlobalApplication.onCreate(GlobalApplication.kt:17)

这里有两种可能性。

一种情况是你的应用程序是com.chugnchunon.chungchunon_android(请参见堆栈跟踪代码片段的底部)。如果是这样,那么你正在使用com.kakao.auth.KakaoSDK(请参见堆栈跟踪代码片段的倒数第二行),它是创建破损的PendingIntent的原因。 你需要更新你的应用程序,使用包含该 KakaoSDK类的新版本库,或联系其开发人员并指出问题。

另一种情况是com.chugnchunon.chungchunon_android.GlobalApplication本身来自一个库,并且正在使用KakaoSDK。 在这种情况下,你需要升级到包含com.chugnchunon.chungchunon_android.GlobalApplication类的新版本库,或者联系其开发人员并指出问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接