From eadc419e66779f9bd51da4f81e5300edef3e4de1 Mon Sep 17 00:00:00 2001 From: xtc Date: Tue, 1 Nov 2022 09:18:22 +0800 Subject: [PATCH] compatible with android 12 --- .idea/misc.xml | 2 +- app/build.gradle | 4 +- app/src/main/AndroidManifest.xml | 22 +++++++++- .../main/java/ttlock/demo/MainActivity.java | 6 +++ .../ttlock/demo/lock/ScanLockActivity.java | 14 +++++-- .../main/java/ttlock/demo/utils/AppUtil.java | 40 +++++++++++++++++++ build.gradle | 6 +-- gradle/wrapper/gradle-wrapper.properties | 4 +- 8 files changed, 85 insertions(+), 13 deletions(-) create mode 100644 app/src/main/java/ttlock/demo/utils/AppUtil.java diff --git a/.idea/misc.xml b/.idea/misc.xml index 7a0e8d9..758b48d 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -43,7 +43,7 @@ - + diff --git a/app/build.gradle b/app/build.gradle index 2a681f9..2fad26c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,11 +1,11 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 28 + compileSdkVersion 31 defaultConfig { applicationId "ttlock.demo" minSdkVersion 23 - targetSdkVersion 28 + targetSdkVersion 31 versionCode 1 versionName "1.0" testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 64fd03a..dafaf41 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -3,13 +3,31 @@ xmlns:tools="http://schemas.android.com/tools" package="ttlock.demo"> - - + + + + + + + = 31) { + return true; + } + return false; + } + + public static int getAndroidSDKVersion() { + int version = 0; + try { + version = Integer.valueOf(Build.VERSION.SDK_INT); + } catch (NumberFormatException e) { + e.printStackTrace(); + } + return version; + } + + public static boolean checkPermission(Activity activity, String permission) { + if (ContextCompat.checkSelfPermission(activity, permission) != PackageManager.PERMISSION_GRANTED) { + activity.requestPermissions(new String[]{permission}, REQUEST_PERMISSION_REQ_CODE); + return false; + } + return true; + } + + +} diff --git a/build.gradle b/build.gradle index 7536b9b..cafa0ce 100644 --- a/build.gradle +++ b/build.gradle @@ -30,9 +30,9 @@ ext { // Sdk and tools // Support library and architecture components support minSdk 14 and above. minSdkVersion = 18 - targetSdkVersion = 23 - compileSdkVersion = 28 - buildToolsVersion = '28.0.3' + targetSdkVersion = 31 + compileSdkVersion = 31 + buildToolsVersion = '31.0.0' // App dependencies supportLibraryVersion = '28.0.0' lifecycle_version = "1.1.1" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 836a757..eb7cf31 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Fri Nov 29 12:55:43 CST 2019 +#Tue Oct 18 16:32:06 CST 2022 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip