Fix widget clicks for older Android versions

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-05-21 14:20:01 +02:00
parent ae5bbf1ab8
commit 7e7c7e676c
No known key found for this signature in database
GPG key ID: 4E577DC593B59BDF

View file

@ -84,7 +84,7 @@ class DashboardWidgetUpdater @Inject constructor(
context, context,
0, 0,
intent, intent,
getPendingIntentFlags() pendingIntentFlags
) )
remoteViews.setPendingIntentTemplate(R.id.list, pendingIntent) remoteViews.setPendingIntentTemplate(R.id.list, pendingIntent)
@ -123,7 +123,7 @@ class DashboardWidgetUpdater @Inject constructor(
context, context,
appWidgetId, appWidgetId,
intent, intent,
getPendingIntentFlags() pendingIntentFlags
) )
} }
@ -138,17 +138,17 @@ class DashboardWidgetUpdater @Inject constructor(
context, context,
appWidgetId, appWidgetId,
intent, intent,
getPendingIntentFlags() pendingIntentFlags
) )
} }
private fun getPendingIntentFlags(): Int { private val pendingIntentFlags: Int = when {
return PendingIntent.FLAG_UPDATE_CURRENT or if (Build.VERSION.SDK_INT >= 34) { Build.VERSION.SDK_INT >= 34 -> {
PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT
} else if (Build.VERSION.SDK_INT >= 31) { }
PendingIntent.FLAG_MUTABLE
} else { else -> {
PendingIntent.FLAG_IMMUTABLE PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
} }
} }
// endregion // endregion