相关疑难解决方法(0)

如何解决android api 30+中的“缺少PendingIntent可变性标志”lint警告?

只要我的目标更新SDK30(安卓R),棉绒警告Missing PendingIntent mutability flag出现在我的PendingIntent.FLAG_UPDATE_CURRENT标志时,我想定义PendingIntent

我应该如何处理这个 lint 而不影响应用程序功能?

android lint android-pendingintent

26
推荐指数
12
解决办法
6141
查看次数

针对 Android 12 的清单合并失败

使用 Android Studio 4.2.1,在我的 build.gradle 文件中将 sdk 目标更改为 Android 12 后,出现Manifest merger failed with multiple errors, see logs错误。

Merged Manifest选项卡中显示的错误如下:

Merging Errors: 
Error: Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details. My_App.app main manifest (this file) 
Error: Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has …
Run Code Online (Sandbox Code Playgroud)

android android-manifest android-studio android-12

17
推荐指数
3
解决办法
5839
查看次数

MediaSessionCompat:Targeting S+ (version 31 and above) 要求在创建 PendingIntent 时指定 FLAG_IMMUTABLE 或 FLAG_MUTABLE 之一

我正在尝试将我的应用程序更新到 Android SDK 31,但我遇到了 MediaSessionCompat 问题。

我有一个扩展 MediaBrowserServiceCompat() 的 MediaService,并在该服务的 onCreate 方法中初始化 MediaSessionCompat。

override fun onCreate() {
  super.onCreate()
  mediaSession = MediaSessionCompat(this, TAG).apply {
    setCallback(mediaSessionCallback)
    isActive = true
  }
...
Run Code Online (Sandbox Code Playgroud)

但我有以下错误

java.lang.RuntimeException: Unable to create service com.radio.core.service.MediaService: java.lang.IllegalArgumentException: com.xxx.xxx: 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 …
Run Code Online (Sandbox Code Playgroud)

java android android-mediaplayer kotlin android-studio

5
推荐指数
10
解决办法
853
查看次数