Gus*_*arz 6 android dart flutter
E/AndroidRuntime(15886): java.lang.RuntimeException: Unable to get provider androidx.startup.InitializationProvider: androidx.startup.StartupException: java.lang.IllegalArgumentException: br.com.cspautomacao.lazarus_comanda: Targeting U+ (version 34 and above) disallows creating or retrieving a PendingIntent with FLAG_MUTABLE, an implicit Intent within and without FLAG_NO_CREATE and FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT for security reasons. To retrieve an already existing PendingIntent, use FLAG_NO_CREATE, however, to create a new PendingIntent with an implicit Intent use FLAG_IMMUTABLE.
我更新到 Android SDK 34 后开始出现此错误。
\n我的依赖项:
\ndependencies {\n implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"\n \n // Depend\xc3\xaancias comuns\n implementation fileTree(dir: "libs/comun", include: ['*.aar'])\n implementation 'androidx.work:work-runtime-ktx:2.8.1'\n implementation 'androidx.appcompat:appcompat:1.6.1' \n\n // Depend\xc3\xaancias "elgin"\n implementation fileTree(dir: 'libs/elgin', include: ['*.aar'])\n implementation 'org.apache.commons:commons-lang3:3.9'\n implementation 'com.google.code.gson:gson:2.8.6'\n}\nRun Code Online (Sandbox Code Playgroud)\n
该错误表示,从 Android 14 (API 34) 开始,如果您在带有 FLAG_MUTABLE 的 PendingIntent 对象中有隐式意图,您的应用程序将会崩溃。
如果您不需要FLAG_MUTABLE标志,则只需将其更改为FLAG_IMMUTABLE。但是,如果您的应用程序需要可变意图,那么我建议采用以下解决方案之一:
val implicitIntent = Intent("com.example.app.action.WHATEVER")
val implicitPendingIntent = if (Build.VERSION.SDK_INT >= 34) {
PendingIntent.getBroadcast(this, 0, implicitIntent, PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT)
} else {
PendingIntent.getBroadcast(this, 0, implicitIntent, PendingIntent.FLAG_MUTABLE)
}
Run Code Online (Sandbox Code Playgroud)
通过提供目标应用程序的包名称或完全限定的组件类名称来明确您的意图。
val explicitIntent = Intent("com.example.app.action.WHATEVER")
explicitIntent.setPackage(context.packageName)
// explicitIntent.component = ComponentName("com.example.app", "com.example.app.MainActivity")
val explicitPendingIntent = PendingIntent.getBroadcast(this, 0, explicitIntent, PendingIntent.FLAG_MUTABLE)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1564 次 |
| 最近记录: |