Skip to content

Commit 09f4799

Browse files
Fixed: Add PendingIntent immutability flags to prevent Warning: Missing PendingIntent mutability flag [UnspecifiedImmutableFlag] error
- https://developer.android.com/about/versions/12/behavior-changes-12#pending-intent-mutability
1 parent 61030a9 commit 09f4799

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

app/src/main/java/com/termux/window/TermuxFloatService.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ private Notification buildNotification() {
138138

139139
final String intentAction = mVisibleWindow ? TERMUX_FLOAT_SERVICE.ACTION_HIDE : TERMUX_FLOAT_SERVICE.ACTION_SHOW;
140140
Intent notificationIntent = new Intent(this, TermuxFloatService.class).setAction(intentAction);
141-
PendingIntent contentIntent = PendingIntent.getService(this, 0, notificationIntent, 0);
141+
PendingIntent contentIntent = PendingIntent.getService(this, 0, notificationIntent,
142+
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.FLAG_IMMUTABLE : 0);
142143

143144
// Build the notification
144145
Notification.Builder builder = NotificationUtils.geNotificationBuilder(this,
@@ -161,7 +162,9 @@ private Notification buildNotification() {
161162

162163
// Set Exit button action
163164
Intent exitIntent = new Intent(this, TermuxFloatService.class).setAction(TERMUX_FLOAT_SERVICE.ACTION_STOP_SERVICE);
164-
builder.addAction(android.R.drawable.ic_delete, res.getString(R.string.notification_action_exit), PendingIntent.getService(this, 0, exitIntent, 0));
165+
builder.addAction(android.R.drawable.ic_delete, res.getString(R.string.notification_action_exit),
166+
PendingIntent.getService(this, 0, exitIntent,
167+
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.FLAG_IMMUTABLE : 0));
165168

166169
return builder.build();
167170
}

0 commit comments

Comments
 (0)