From 22972373e5a9a74250971eb869c626ae6397ad76 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 13 Sep 2021 21:57:45 -0700 Subject: Fix pending intent for Android 12 --- .../kotlin/com/pitchedapps/frost/services/FrostNotifications.kt | 8 ++++++-- .../kotlin/com/pitchedapps/frost/widgets/NotificationWidget.kt | 6 +++++- app/src/main/play/en-US/whatsnew | 3 ++- app/src/main/res/xml/frost_changelog.xml | 1 + 4 files changed, 14 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt index 5b260dee..e050ad5a 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt @@ -59,6 +59,10 @@ import kotlin.math.abs */ private val _40_DP = 40.dpToPx +private val pendingIntentFlagUpdateCurrent: Int + get() = PendingIntent.FLAG_UPDATE_CURRENT or + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0 + /** * Enum to handle notification creations */ @@ -227,7 +231,7 @@ enum class NotificationType( putContentExtra(intent, content) val group = "${groupPrefix}_${data.id}" val pendingIntent = - PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) + PendingIntent.getActivity(context, 0, intent, pendingIntentFlagUpdateCurrent) val notifBuilder = context.frostNotification(channelId) .setContentTitle(title ?: context.string(R.string.frost_name)) .setContentText(text) @@ -266,7 +270,7 @@ enum class NotificationType( intent.data = Uri.parse(fbItem.url) val group = "${groupPrefix}_$userId" val pendingIntent = - PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) + PendingIntent.getActivity(context, 0, intent, pendingIntentFlagUpdateCurrent) val notifBuilder = context.frostNotification(channelId) .setContentTitle(context.string(R.string.frost_name)) .setContentText("$count ${context.string(fbItem.titleId)}") diff --git a/app/src/main/kotlin/com/pitchedapps/frost/widgets/NotificationWidget.kt b/app/src/main/kotlin/com/pitchedapps/frost/widgets/NotificationWidget.kt index 9c5fbb7d..d610a535 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/widgets/NotificationWidget.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/widgets/NotificationWidget.kt @@ -86,7 +86,7 @@ class NotificationWidget : AppWidgetProvider() { context, 0, type.createCommonIntent(context, userId), - PendingIntent.FLAG_UPDATE_CURRENT + pendingIntentFlagUpdateCurrent ) views.setPendingIntentTemplate(R.id.widget_notification_list, pendingIntentTemplate) @@ -96,6 +96,10 @@ class NotificationWidget : AppWidgetProvider() { appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.widget_notification_list) } + private val pendingIntentFlagUpdateCurrent: Int + get() = PendingIntent.FLAG_UPDATE_CURRENT or + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0 + companion object { fun forceUpdate(context: Context) { val manager = AppWidgetManager.getInstance(context) diff --git a/app/src/main/play/en-US/whatsnew b/app/src/main/play/en-US/whatsnew index ea4ee41f..f9e930b8 100644 --- a/app/src/main/play/en-US/whatsnew +++ b/app/src/main/play/en-US/whatsnew @@ -2,4 +2,5 @@ v3.1.0 * Fix multi account sign in * Only clear out cookies on explicit logout; Facebook logout redirects no longer erase cookies -* Update themes \ No newline at end of file +* Update themes +* Big infra changes (please file bugs for new crashes) \ No newline at end of file diff --git a/app/src/main/res/xml/frost_changelog.xml b/app/src/main/res/xml/frost_changelog.xml index ed3ea6e7..292d62bb 100644 --- a/app/src/main/res/xml/frost_changelog.xml +++ b/app/src/main/res/xml/frost_changelog.xml @@ -10,6 +10,7 @@ + -- cgit v1.2.3