Skip to content

Commit

Permalink
fix: Android 12 crash on closing notification drawer
Browse files Browse the repository at this point in the history
See: #1543
  • Loading branch information
vincent-paing committed Mar 15, 2022
1 parent ac8c2a7 commit a142257
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@

package com.onesignal;

import static com.onesignal.GenerateNotification.BUNDLE_KEY_ANDROID_NOTIFICATION_ID;
import static com.onesignal.GenerateNotification.BUNDLE_KEY_ONESIGNAL_DATA;

import android.app.Activity;
import android.app.NotificationManager;
import android.content.ContentValues;
Expand All @@ -44,9 +47,6 @@
import org.json.JSONException;
import org.json.JSONObject;

import static com.onesignal.GenerateNotification.BUNDLE_KEY_ANDROID_NOTIFICATION_ID;
import static com.onesignal.GenerateNotification.BUNDLE_KEY_ONESIGNAL_DATA;

// Process both notifications opens and dismisses.
class NotificationOpenedProcessor {

Expand Down Expand Up @@ -74,7 +74,13 @@ private static void handleDismissFromActionButtonPress(Context context, Intent i
// Pressed an action button, need to clear the notification and close the notification area manually.
if (intent.getBooleanExtra("action_button", false)) {
NotificationManagerCompat.from(context).cancel(intent.getIntExtra(BUNDLE_KEY_ANDROID_NOTIFICATION_ID, 0));
context.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));

//Close notification drawer user override targetSdkVersion to be lower than Android 11
// See https://developer.android.com/about/versions/12/behavior-changes-all#close-system-dialogs
int targetSdkVersion = context.getApplicationContext().getApplicationInfo().targetSdkVersion;
if (targetSdkVersion < Build.VERSION_CODES.S ) {
context.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
}
}
}

Expand Down

0 comments on commit a142257

Please sign in to comment.