0

Trying to add reply action to the notifications But no matter what I make, still gives me this error:

PendingIntents attached to actions with remote inputs must be mutable

app/build.gradle:

android {
  compileSdkVersion 33
  ndkVersion '23.1.7779620'

  defaultConfig {
    minSdkVersion 23
    targetSdkVersion flutter.targetSdkVersion
  }

  dependencies {
    implementation "com.android.support:support-compat:28.0.0"
    implementation 'androidx.work:work-runtime-ktx:2.7.1'
    implementation 'androidx.preference:preference-ktx:1.2.0'
  }
}

PendingIntent:

PendingIntent replyPendingIntent;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
      replyPendingIntent =
              PendingIntent.getActivity(getApplicationContext(), channel.uuid.hashCode(), replyIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
    } else {
      replyPendingIntent =
              PendingIntent.getActivity(getApplicationContext(), channel.uuid.hashCode(), replyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    }

RemoteInput:

RemoteInput remoteInput = new RemoteInput.Builder("reply_chat")
            .setLabel("Reply")
            .build();

NotificationCompat.Action:

NotificationCompat.Action replyAction =
            new NotificationCompat.Action.Builder(
                    R.drawable.ic_verified_badge,
                    "Reply", replyPendingIntent)
                    .addRemoteInput(remoteInput)
                    .build();
Khader Murtaja
  • 425
  • 1
  • 5
  • 15
  • Try replacing `PendingIntent.FLAG_IMMUTABLE` with `PendingIntent.FLAG_MUTABLE`. – CommonsWare Aug 15 '22 at 13:02
  • @CommonsWare gives me error that it is not a correct variable to be there – Khader Murtaja Aug 15 '22 at 13:05
  • What is the exact error message? – CommonsWare Aug 15 '22 at 13:15
  • @CommonsWare Must be one or more of: PendingIntent.FLAG_ONE_SHOT, PendingIntent.FLAG_NO_CREATE, PendingIntent.FLAG_CANCEL_CURRENT, PendingIntent.FLAG_UPDATE_CURRENT, PendingIntent.FLAG_IMMUTABLE, android.app.PendingIntent.FLAG_MUTABLE, Intent.FILL_IN_ACTION, Intent.FILL_IN_DATA, Intent.FILL_IN_CATEGORIES, Intent.FILL_IN_COMPONENT, Intent.FILL_IN_PACKAGE, Intent.FILL_IN_SOURCE_BOUNDS, Intent.FILL_IN_SELECTOR, Intent.FILL_IN_CLIP_DATA – Khader Murtaja Aug 15 '22 at 13:37
  • `FLAG_MUTABLE` is in that list. – CommonsWare Aug 15 '22 at 14:27

0 Answers0