From 2dff3d9191615284b019cb29b8ecaa7b5efaffd6 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Tue, 26 Oct 2021 12:46:30 +0200 Subject: [PATCH] Use FLAG_IMMUTABLE as required by android 12 (#366) --- app/build.gradle | 11 ++++++----- .../readerforselfoss/background/background.kt | 9 +++++++-- .../bou/readerforselfoss/utils/LinksUtils.kt | 16 +++++++++++----- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a70bcd8..66044df 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -36,7 +36,7 @@ android { targetCompatibility JavaVersion.VERSION_1_8 } compileSdkVersion 31 - buildToolsVersion '30.0.3' + buildToolsVersion '31.0.0' buildFeatures { viewBinding true } @@ -109,6 +109,7 @@ dependencies { implementation "androidx.browser:browser:1.3.0" implementation "androidx.cardview:cardview:$android_version" implementation "androidx.annotation:annotation:1.2.0" + implementation 'androidx.work:work-runtime-ktx:2.7.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.1' implementation 'org.jsoup:jsoup:1.13.1' @@ -121,7 +122,7 @@ dependencies { } // Async - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2' // Retrofit + http logging + okhttp implementation 'com.squareup.retrofit2:retrofit:2.9.0' @@ -151,13 +152,13 @@ dependencies { //PhotoView implementation 'com.github.chrisbanes:PhotoView:2.0.0' - implementation 'androidx.core:core-ktx:1.7.0-beta02' + implementation 'androidx.core:core-ktx:1.7.0-rc01' implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.4.0-rc01" implementation "androidx.lifecycle:lifecycle-common-java8:2.4.0-rc01" - implementation "androidx.room:room-ktx:2.4.0-alpha05" - kapt "androidx.room:room-compiler:2.4.0-alpha05" + implementation "androidx.room:room-ktx:2.4.0-beta01" + kapt "androidx.room:room-compiler:2.4.0-beta01" implementation "android.arch.work:work-runtime-ktx:$work_version" } diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/background/background.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/background/background.kt index 50cfd56..1f0ba92 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/background/background.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/background/background.kt @@ -4,6 +4,7 @@ import android.app.NotificationManager import android.app.PendingIntent import android.content.Context import android.content.Intent +import android.os.Build import android.preference.PreferenceManager import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat.PRIORITY_DEFAULT @@ -117,8 +118,12 @@ override fun doWork(): Result { val intent = Intent(context, MainActivity::class.java).apply { flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK } - val pendingIntent: PendingIntent = - PendingIntent.getActivity(context, 0, intent, 0) + val pflags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + PendingIntent.FLAG_IMMUTABLE + } else { + 0 + } + val pendingIntent: PendingIntent = PendingIntent.getActivity(context, 0, intent, pflags) val newItemsNotification = NotificationCompat.Builder(applicationContext, Config.newItemsChannelId) diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/utils/LinksUtils.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/utils/LinksUtils.kt index 94b1639..eb59947 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/utils/LinksUtils.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/utils/LinksUtils.kt @@ -7,6 +7,7 @@ import android.content.Context import android.content.Intent import android.graphics.BitmapFactory import android.net.Uri +import android.os.Build import android.text.Spannable import android.text.style.ClickableSpan import androidx.browser.customtabs.CustomTabsIntent @@ -26,12 +27,17 @@ fun Context.buildCustomTabsIntent(): CustomTabsIntent { val actionIntent = Intent(Intent.ACTION_SEND) actionIntent.type = "text/plain" - val createPendingShareIntent: PendingIntent = PendingIntent.getActivity( - this, - 0, - actionIntent, + val pflags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + PendingIntent.FLAG_IMMUTABLE + } else { 0 - ) + } + val createPendingShareIntent: PendingIntent = PendingIntent.getActivity( + this, + 0, + actionIntent, + pflags + ) val intentBuilder = CustomTabsIntent.Builder()