Skip to content

Commit

Permalink
Fix crash
Browse files Browse the repository at this point in the history
  • Loading branch information
james58899 committed Mar 28, 2023
1 parent e0da467 commit fa2c335
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) }
}
}
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/one/oktw/muzeipixivsource/util/APICompat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ inline fun <reified T : Parcelable> 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)
}
}

Expand Down

0 comments on commit fa2c335

Please sign in to comment.