Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue PendingIntent.FLAG_IMMUTABLE app crashed on Android app Target 31 (Android 12) #308

Open
thongbbc opened this issue Jul 5, 2022 · 2 comments

Comments

@thongbbc
Copy link

thongbbc commented Jul 5, 2022

Hello, we have been having this issue on Android app Target 31.
Ref document: https://stackoverflow.com/questions/67045607/how-to-resolve-missing-pendingintent-mutability-flag-lint-warning-in-android-a

I tried with solution add dependency into build.gradle
implementation 'androidx.work:work-runtime:2.7.1'

But it still does not work.

-> My latest solution to fix this which is using patch package to modify Native code

class NotificationActions {
  var INTENT_ACTION = "com.vydia.RNUploader.notification.action"
  class NotificationActions {
    val intent = Intent(INTENT_ACTION)
    intent.putExtra(PARAM_ACTION, ACTION_CANCEL_UPLOAD)
    intent.putExtra(PARAM_UPLOAD_ID, uploadID)
    eturn PendingIntent.getBroadcast(context, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT)
    val flag =
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
    else PendingIntent.FLAG_UPDATE_CURRENT

    return PendingIntent.getBroadcast(context, requestCode, intent, flag)
  }
}

Change return PendingIntent.getBroadcast(context, requestCode, intent, flag) to

    val flag =
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE else PendingIntent.FLAG_UPDATE_CURRENT

    return PendingIntent.getBroadcast(context, requestCode, intent, flag)

I think we should create PR for this. Thanks.

@xOIBrandon
Copy link

We are in the process of updating android to 31 and we ran into this also. Reading the readme for the android-upload-service library I noticed a warning that says that in 31 you can't start uploads while your app is in the background. Do you have any experience dealing with this b/c it seems like its breaks the Android side of this library.

Android 5.0 (API 21) to Android 12 (API 31) support. Beware you cannot start uploads while your app is the background on Android 12 due to recent Service limitations

It doesn't seem like android-upload-service has not plans to make background uploads work for 31 and up either
statement from the author 1
statement from the author 2

@dmalfaro
Copy link

Hello, we have been having this issue on Android app Target 31. Ref document: https://stackoverflow.com/questions/67045607/how-to-resolve-missing-pendingintent-mutability-flag-lint-warning-in-android-a

I tried with solution add dependency into build.gradle implementation 'androidx.work:work-runtime:2.7.1'

But it still does not work.

-> My latest solution to fix this which is using patch package to modify Native code

class NotificationActions {
  var INTENT_ACTION = "com.vydia.RNUploader.notification.action"
  class NotificationActions {
    val intent = Intent(INTENT_ACTION)
    intent.putExtra(PARAM_ACTION, ACTION_CANCEL_UPLOAD)
    intent.putExtra(PARAM_UPLOAD_ID, uploadID)
    eturn PendingIntent.getBroadcast(context, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT)
    val flag =
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
    else PendingIntent.FLAG_UPDATE_CURRENT

    return PendingIntent.getBroadcast(context, requestCode, intent, flag)
  }
}

Change return PendingIntent.getBroadcast(context, requestCode, intent, flag) to

    val flag =
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE else PendingIntent.FLAG_UPDATE_CURRENT

    return PendingIntent.getBroadcast(context, requestCode, intent, flag)

I think we should create PR for this. Thanks.

My NotificationActions class is different than yours here is the content of my file

`package com.vydia.RNUploader

import android.app.PendingIntent
import android.content.Context
import android.content.Intent

class NotificationActions {
var INTENT_ACTION = "com.vydia.RNUploader.notification.action"

val PARAM_ACTION = "action"
val PARAM_UPLOAD_ID = "uploadId"

val ACTION_CANCEL_UPLOAD = "cancelUpload"

fun getCancelUploadAction(context: Context?,
requestCode: Int,
uploadID: String?): PendingIntent? {
val intent = Intent(INTENT_ACTION)
intent.putExtra(PARAM_ACTION, ACTION_CANCEL_UPLOAD)
intent.putExtra(PARAM_UPLOAD_ID, uploadID)
return PendingIntent.getBroadcast(context, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT)
}
}`

How should I edit the return line, I tried your solution but its throwing some errors.
My react-native-background-upload version is ^6.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants