Set FLAG_IMMUTABLE on the intent of the lock status notification

This fixes a crash on API 31
This commit is contained in:
Alexander Bakker 2022-02-02 21:01:15 +01:00
parent 3d13117752
commit 473cb7bfeb

View file

@ -1,8 +1,10 @@
package com.beemdevelopment.aegis.services; package com.beemdevelopment.aegis.services;
import android.annotation.SuppressLint;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.app.Service; import android.app.Service;
import android.content.Intent; import android.content.Intent;
import android.os.Build;
import android.os.IBinder; import android.os.IBinder;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -24,9 +26,14 @@ public class NotificationService extends Service {
return Service.START_STICKY; return Service.START_STICKY;
} }
@SuppressLint("LaunchActivityFromNotification")
public void serviceMethod() { public void serviceMethod() {
int flags = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
flags |= PendingIntent.FLAG_IMMUTABLE;
}
Intent intentAction = new Intent(CODE_LOCK_VAULT_ACTION); Intent intentAction = new Intent(CODE_LOCK_VAULT_ACTION);
PendingIntent lockDatabaseIntent = PendingIntent.getBroadcast(this, 1, intentAction, 0); PendingIntent lockDatabaseIntent = PendingIntent.getBroadcast(this, 1, intentAction, flags);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CODE_LOCK_STATUS_ID) NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CODE_LOCK_STATUS_ID)
.setSmallIcon(R.drawable.ic_fingerprint_black_24dp) .setSmallIcon(R.drawable.ic_fingerprint_black_24dp)
.setContentTitle(getString(R.string.app_name_full)) .setContentTitle(getString(R.string.app_name_full))