0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-19 19:42:17 +02:00

build: bump compileSdkVersion to 33

This commit is contained in:
Mike Hardy 2022-09-08 23:37:57 -05:00 committed by Brayan Oliveira
parent 3f464f6f4c
commit 2eeed6570e
3 changed files with 26 additions and 10 deletions

View File

@ -26,7 +26,7 @@ idea {
def homePath = System.properties['user.home']
android {
compileSdkVersion 32 // change api compileSdkVersion at the same time
compileSdkVersion 33 // change api compileSdkVersion at the same time
defaultConfig {
applicationId "com.ichi2.anki"

View File

@ -12,7 +12,7 @@ repositories {
mavenCentral()
}
android {
compileSdkVersion 32
compileSdkVersion 33
defaultConfig {
minSdkVersion 14

View File

@ -584,16 +584,26 @@ class AddContentApi(context: Context) {
* @return the spec version number or -1 if AnkiDroid is not installed.
*/
// TODO: Kotlin Cleanup - val or fun - likely needs JvmField either way.
@Suppress("deprecation") // API33 symbol required until minSdkVersion >= 33
val apiHostSpecVersion: Int
get() {
// PackageManager#resolveContentProvider docs suggest flags should be 0 (but that gives null metadata)
// GET_META_DATA seems to work anyway
val info = mContext.packageManager.resolveContentProvider(
FlashCardsContract.AUTHORITY,
PackageManager.GET_META_DATA
)
?: return -1
return if (info.metaData != null && info.metaData.containsKey(
val info =
if (Build.VERSION.SDK_INT >= 33)
mContext.packageManager.resolveContentProvider(
FlashCardsContract.AUTHORITY,
PackageManager.ComponentInfoFlags.of(
PackageManager.GET_META_DATA.toLong()
)
)
else
mContext.packageManager.resolveContentProvider(
FlashCardsContract.AUTHORITY,
PackageManager.GET_META_DATA
)
return if (info?.metaData != null && info.metaData.containsKey(
PROVIDER_SPEC_META_DATA_KEY
)
) {
@ -816,10 +826,16 @@ class AddContentApi(context: Context) {
* @return packageId of AnkiDroid if a supported version is not installed, otherwise null
*/
// TODO: Kotlin Cleanup: simplify into one line fun
@Suppress("deprecation") // deprecated symbol until minSdkVersion >= 33
fun getAnkiDroidPackageName(context: Context): String? {
val manager = context.packageManager
val pi = manager.resolveContentProvider(FlashCardsContract.AUTHORITY, 0)
return pi?.packageName
return if (Build.VERSION.SDK_INT >= 33)
manager.resolveContentProvider(
FlashCardsContract.AUTHORITY,
PackageManager.ComponentInfoFlags.of(0L)
)?.packageName
else
manager.resolveContentProvider(FlashCardsContract.AUTHORITY, 0)?.packageName
}
}