From 1f1c782772a80bfac4d6d3bc35858232c88c7cfb Mon Sep 17 00:00:00 2001 From: tom5079 Date: Tue, 4 Jan 2022 23:15:34 +0900 Subject: [PATCH] 5.2.7 Fix app crashing on Android 12 --- .idea/deploymentTargetDropDown.xml | 17 +++++++++++++++++ .../pupil/receiver/UpdateBroadcastReceiver.kt | 3 ++- .../quaver/pupil/services/DownloadService.kt | 5 +++-- 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 .idea/deploymentTargetDropDown.xml diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml new file mode 100644 index 00000000..784f98ae --- /dev/null +++ b/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/xyz/quaver/pupil/receiver/UpdateBroadcastReceiver.kt b/app/src/main/java/xyz/quaver/pupil/receiver/UpdateBroadcastReceiver.kt index 3097bfae..9fe48e1a 100644 --- a/app/src/main/java/xyz/quaver/pupil/receiver/UpdateBroadcastReceiver.kt +++ b/app/src/main/java/xyz/quaver/pupil/receiver/UpdateBroadcastReceiver.kt @@ -24,6 +24,7 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.net.Uri +import android.os.Build import android.webkit.MimeTypeMap import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat @@ -76,7 +77,7 @@ class UpdateBroadcastReceiver : BroadcastReceiver() { val pendingIntent = PendingIntent.getActivity(context, 0, Intent(Intent.ACTION_VIEW).apply { flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_ACTIVITY_NEW_TASK setDataAndType(uri, MimeTypeMap.getSingleton().getMimeTypeFromExtension("apk")) - }, 0) + }, if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) PendingIntent.FLAG_IMMUTABLE else 0) val notification = NotificationCompat.Builder(context, "update") .setSmallIcon(android.R.drawable.stat_sys_download_done) diff --git a/app/src/main/java/xyz/quaver/pupil/services/DownloadService.kt b/app/src/main/java/xyz/quaver/pupil/services/DownloadService.kt index 30891bce..3413c1e0 100644 --- a/app/src/main/java/xyz/quaver/pupil/services/DownloadService.kt +++ b/app/src/main/java/xyz/quaver/pupil/services/DownloadService.kt @@ -23,6 +23,7 @@ import android.app.PendingIntent import android.app.Service import android.content.Context import android.content.Intent +import android.os.Build import android.util.Log import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat @@ -74,7 +75,7 @@ class DownloadService : Service() { val pendingIntent = TaskStackBuilder.create(this).run { addNextIntentWithParentStack(intent) - getPendingIntent(galleryID, PendingIntent.FLAG_UPDATE_CURRENT) + getPendingIntent(galleryID, PendingIntent.FLAG_UPDATE_CURRENT or if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) PendingIntent.FLAG_MUTABLE else 0) } val action = NotificationCompat.Action.Builder(0, getText(android.R.string.cancel), @@ -84,7 +85,7 @@ class DownloadService : Service() { Intent(this, DownloadService::class.java) .putExtra(KEY_COMMAND, COMMAND_CANCEL) .putExtra(KEY_ID, galleryID), - PendingIntent.FLAG_UPDATE_CURRENT), + PendingIntent.FLAG_UPDATE_CURRENT or if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) PendingIntent.FLAG_MUTABLE else 0), ).build() notification[galleryID] = NotificationCompat.Builder(this, "download").apply {