aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2021-09-13 21:57:45 -0700
committerAllan Wang <me@allanwang.ca>2021-09-13 21:57:45 -0700
commit22972373e5a9a74250971eb869c626ae6397ad76 (patch)
tree311ce3b9da0279bd00877c94e10c7934b416a7cb /app/src/main/kotlin
parentd4c64b800ffcfd5590c3a18c8bf5cf75ee74f3b4 (diff)
downloadfrost-22972373e5a9a74250971eb869c626ae6397ad76.tar.gz
frost-22972373e5a9a74250971eb869c626ae6397ad76.tar.bz2
frost-22972373e5a9a74250971eb869c626ae6397ad76.zip
Fix pending intent for Android 12
Diffstat (limited to 'app/src/main/kotlin')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt8
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/widgets/NotificationWidget.kt6
2 files changed, 11 insertions, 3 deletions
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)