Skip to content

Commit 542bce1

Browse files
Merge pull request #2603 from nextcloud/pendingIntent
fix pendingIntent
2 parents 7b7a1ab + 629c004 commit 542bce1

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

app/src/main/java/it/niedermann/owncloud/notes/shared/util/WidgetUtil.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,21 @@ private WidgetUtil() {
1616
}
1717

1818
/**
19-
* Android S requires either {@link PendingIntent#FLAG_MUTABLE} or
20-
* {@link PendingIntent#FLAG_IMMUTABLE} to be set on a {@link PendingIntent}.
21-
* This is enforced by Android and will lead to an app crash if neither of those flags is
22-
* present.
23-
* To keep the app working, this compatibility method can be used to add the
24-
* {@link PendingIntent#FLAG_MUTABLE} flag on Android S and higher to restore the behavior of
25-
* older SDK versions.
19+
* Android 14 (API 34) and above require FLAG_IMMUTABLE
2620
*
27-
* @param flags wanted flags for {@link PendingIntent}
28-
* @return {@param flags} | {@link PendingIntent#FLAG_MUTABLE}
21+
* <p>
22+
* Android 12 (API 31) and above allow FLAG_MUTABLE
23+
*
24+
* <p>
25+
* Ensures compatibility with different Android API levels by setting appropriate flags for a PendingIntent.
26+
*
27+
* @param flags The original flags to be used for the PendingIntent.
28+
* @return The modified flags with compatibility adjustments based on the Android API level.
2929
*/
3030
public static int pendingIntentFlagCompat(int flags) {
31+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
32+
return flags | PendingIntent.FLAG_IMMUTABLE;
33+
}
3134
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
3235
return flags | PendingIntent.FLAG_MUTABLE;
3336
}

0 commit comments

Comments
 (0)