From fa2c33514a57b76d4f059e6152bca013840d7b3c Mon Sep 17 00:00:00 2001 From: James58899 Date: Tue, 28 Mar 2023 09:19:33 +0800 Subject: [PATCH] Fix crash --- .../muzeipixivsource/activity/fragment/SettingsFragment.kt | 3 +-- .../main/java/one/oktw/muzeipixivsource/util/APICompat.kt | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/one/oktw/muzeipixivsource/activity/fragment/SettingsFragment.kt b/app/src/main/java/one/oktw/muzeipixivsource/activity/fragment/SettingsFragment.kt index 56a6315..7e0c941 100644 --- a/app/src/main/java/one/oktw/muzeipixivsource/activity/fragment/SettingsFragment.kt +++ b/app/src/main/java/one/oktw/muzeipixivsource/activity/fragment/SettingsFragment.kt @@ -2,7 +2,6 @@ package one.oktw.muzeipixivsource.activity.fragment import android.content.ComponentName import android.content.Intent -import android.content.pm.PackageManager import android.os.Bundle import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts @@ -165,7 +164,7 @@ class SettingsFragment : PreferenceFragmentCompat() { if (newValue != null) { val context = requireContext() - ProviderContract.getContentUri(context.packageManager.getProviderInfoCompat(ComponentName(context, MuzeiProvider::class.java), PackageManager.ComponentInfoFlags.of(0)).authority) + ProviderContract.getContentUri(context.packageManager.getProviderInfoCompat(ComponentName(context, MuzeiProvider::class.java), 0).authority) .let { context.contentResolver.delete(it, null, null) } } } diff --git a/app/src/main/java/one/oktw/muzeipixivsource/util/APICompat.kt b/app/src/main/java/one/oktw/muzeipixivsource/util/APICompat.kt index 3870c02..ce570a2 100644 --- a/app/src/main/java/one/oktw/muzeipixivsource/util/APICompat.kt +++ b/app/src/main/java/one/oktw/muzeipixivsource/util/APICompat.kt @@ -28,12 +28,12 @@ inline fun Intent.getParcelableExtraCompat(name: String } } -fun PackageManager.getProviderInfoCompat(component: ComponentName, flags: PackageManager.ComponentInfoFlags): ProviderInfo { +fun PackageManager.getProviderInfoCompat(component: ComponentName, flags: Int): ProviderInfo { return if (Build.VERSION.SDK_INT >= 33) { - getProviderInfo(component, flags) + getProviderInfo(component, PackageManager.ComponentInfoFlags.of(flags.toLong())) } else { @Suppress("DEPRECATION") - getProviderInfo(component, flags.value.toInt()) + getProviderInfo(component, flags) } }