diff --git a/.idea/libraries/Dart_SDK.xml b/.idea/libraries/Dart_SDK.xml index 90028fc..126980b 100644 --- a/.idea/libraries/Dart_SDK.xml +++ b/.idea/libraries/Dart_SDK.xml @@ -1,17 +1,26 @@ - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 7ea7b95..0c993d5 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,45 +1,57 @@ - - - - - - - - - - - - - - - - - - - - - + + - - - - - + + + + + + + + - - + + + - + + + + + - + + + + + 1693208233945 + + + + + + + + + + \ No newline at end of file diff --git a/android/build.gradle b/android/build.gradle index 8f97c2e..838e0d6 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -2,22 +2,28 @@ group 'dev.pharsh.sms_user_consent' version '1.0-SNAPSHOT' buildscript { - ext.kotlin_version = '1.3.50' + ext.kotlin_version = '1.6.10' repositories { + mavenCentral() google() - jcenter() + maven { + url "https://plugins.gradle.org/m2/" + } } dependencies { - classpath 'com.android.tools.build:gradle:3.5.0' + classpath 'com.android.tools.build:gradle:7.0.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } rootProject.allprojects { repositories { + mavenCentral() google() - jcenter() + maven { + url "https://plugins.gradle.org/m2/" + } } } @@ -25,7 +31,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' android { - compileSdkVersion 30 + compileSdkVersion 31 sourceSets { main.java.srcDirs += 'src/main/kotlin' @@ -42,6 +48,6 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" // for sms user consent - implementation 'com.google.android.gms:play-services-auth:18.1.0' - implementation 'com.google.android.gms:play-services-auth-api-phone:17.4.0' + implementation 'com.google.android.gms:play-services-auth:20.2.0' + implementation 'com.google.android.gms:play-services-auth-api-phone:18.0.1' } diff --git a/android/gradle.properties b/android/gradle.properties index 38c8d45..94adc3a 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,4 +1,3 @@ org.gradle.jvmargs=-Xmx1536M -android.enableR8=true android.useAndroidX=true android.enableJetifier=true diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index 01a286e..29e4134 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip diff --git a/android/src/main/kotlin/dev/pharsh/sms_user_consent/SmsUserConsentPlugin.kt b/android/src/main/kotlin/dev/pharsh/sms_user_consent/SmsUserConsentPlugin.kt index b4de8fb..9977548 100644 --- a/android/src/main/kotlin/dev/pharsh/sms_user_consent/SmsUserConsentPlugin.kt +++ b/android/src/main/kotlin/dev/pharsh/sms_user_consent/SmsUserConsentPlugin.kt @@ -40,9 +40,8 @@ class SmsUserConsentPlugin : FlutterPlugin, MethodCallHandler, ActivityAware { result.success(null) } "requestSms" -> { - SmsRetriever.getClient(mActivity.applicationContext).startSmsUserConsent(call.argument("senderPhoneNumber")) - - mActivity.registerReceiver(smsVerificationReceiver, IntentFilter(SmsRetriever.SMS_RETRIEVED_ACTION)) + SmsRetriever.getClient(mActivity.applicationContext).startSmsUserConsent(call.argument("senderPhoneNumber")) + mActivity.registerReceiver(smsVerificationReceiver, IntentFilter(SmsRetriever.SMS_RETRIEVED_ACTION), SmsRetriever.SEND_PERMISSION, null) result.success(null) } } @@ -67,13 +66,21 @@ class SmsUserConsentPlugin : FlutterPlugin, MethodCallHandler, ActivityAware { } SMS_CONSENT_REQUEST -> {// Obtain the phone number from the result if (resultCode == Activity.RESULT_OK && data != null) { - channel - .invokeMethod("receivedSms", data.getStringExtra(SmsRetriever.EXTRA_SMS_MESSAGE)) - mActivity.unregisterReceiver(smsVerificationReceiver) + try { + channel.invokeMethod("receivedSms", data.getStringExtra(SmsRetriever.EXTRA_SMS_MESSAGE)) + mActivity.unregisterReceiver(smsVerificationReceiver) + } catch (e: Exception) { + // Avoid crash if receiver is not registered + } } else { // Consent denied. User can type OTC manually. - channel.invokeMethod("receivedSms", null) - mActivity.unregisterReceiver(smsVerificationReceiver) + try { + // Consent denied. User can type OTC manually. + channel.invokeMethod("receivedSms", null) + mActivity.unregisterReceiver(smsVerificationReceiver) + } catch (e: Exception) { + // Avoid crash if receiver is not registered + } } true } @@ -103,6 +110,9 @@ class SmsUserConsentPlugin : FlutterPlugin, MethodCallHandler, ActivityAware { override fun onReceive(context: Context, intent: Intent) { if (SmsRetriever.SMS_RETRIEVED_ACTION == intent.action) { val extras = intent.extras + if (extras == null) { + return; + } val smsRetrieverStatus = extras?.get(SmsRetriever.EXTRA_STATUS) as Status when (smsRetrieverStatus.statusCode) { diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 1f55602..f059b5b 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 30 + compileSdkVersion 31 sourceSets { main.java.srcDirs += 'src/main/kotlin' @@ -40,7 +40,7 @@ android { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "dev.pharsh.sms_user_consent_example" minSdkVersion 16 - targetSdkVersion 28 + targetSdkVersion 31 versionCode flutterVersionCode.toInteger() versionName flutterVersionName } diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index f11e7c4..80f1b4c 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -6,7 +6,7 @@ additional functionality it is fine to subclass or reimplement FlutterApplication and put your custom class here. -->