Merge pull request #49 from acoutts/master

Migrated to android v2 embedding
This commit is contained in:
Rody Davis 2021-09-27 09:00:35 -07:00 committed by GitHub
commit 6b6008c64d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 64 additions and 39 deletions

View File

@ -1,3 +1,7 @@
# 2.3.2
* Update Android plugin to use V2 embedding.
## 2.3.1 ## 2.3.1
* Full null safety * Full null safety

View File

@ -9,7 +9,7 @@ buildscript {
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.5.0' classpath 'com.android.tools.build:gradle:3.5.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
} }
} }
@ -25,7 +25,7 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
android { android {
compileSdkVersion 28 compileSdkVersion 31
sourceSets { sourceSets {
main.java.srcDirs += 'src/main/kotlin' main.java.srcDirs += 'src/main/kotlin'

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

View File

@ -6,36 +6,69 @@ import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result import io.flutter.plugin.common.MethodChannel.Result
import io.flutter.plugin.common.PluginRegistry.Registrar import io.flutter.plugin.common.PluginRegistry.Registrar
import io.flutter.plugin.common.PluginRegistry.ActivityResultListener
import android.app.Activity import android.app.Activity
import android.net.Uri import android.net.Uri
import android.content.Intent import android.content.Intent
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.os.Build import android.os.Build
import androidx.annotation.NonNull
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.embedding.engine.plugins.activity.ActivityAware
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
import io.flutter.plugin.common.BinaryMessenger
class FlutterSmsPlugin(registrar: Registrar) : MethodCallHandler { class FlutterSmsPlugin: FlutterPlugin, MethodCallHandler, ActivityAware {
private lateinit var mChannel: MethodChannel
private var activity: Activity? = null
private val REQUEST_CODE_SEND_SMS = 205 private val REQUEST_CODE_SEND_SMS = 205
var activity: Activity? = null override fun onAttachedToActivity(binding: ActivityPluginBinding) {
private var result: Result? = null activity = binding.activity
}
override fun onDetachedFromActivity() {
activity = null
}
override fun onDetachedFromActivityForConfigChanges() {
activity = null
}
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
activity = binding.activity
}
override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
setupCallbackChannels(flutterPluginBinding.binaryMessenger)
}
override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
teardown()
}
private fun setupCallbackChannels(messenger: BinaryMessenger) {
mChannel = MethodChannel(messenger, "flutter_sms")
mChannel.setMethodCallHandler(this)
}
private fun teardown() {
mChannel.setMethodCallHandler(null)
}
// V1 embedding entry point. This is deprecated and will be removed in a future Flutter
// release but we leave it here in case someone's app does not utilize the V2 embedding yet.
companion object { companion object {
@JvmStatic @JvmStatic
fun registerWith(registrar: Registrar) { fun registerWith(registrar: Registrar) {
val channel = MethodChannel(registrar.messenger(), "flutter_sms") val inst = FlutterSmsPlugin()
channel.setMethodCallHandler(FlutterSmsPlugin(registrar)) inst.activity = registrar.activity()
inst.setupCallbackChannels(registrar.messenger())
} }
} }
init {
this.activity = registrar.activity()
// registrar.addActivityResultListener(this)
}
override fun onMethodCall(call: MethodCall, result: Result) { override fun onMethodCall(call: MethodCall, result: Result) {
this.result = result when (call.method) {
when { "sendSMS" -> {
call.method == "sendSMS" -> {
if (!canSendSMS()) { if (!canSendSMS()) {
result.error( result.error(
"device_not_capable", "device_not_capable",
@ -46,9 +79,8 @@ class FlutterSmsPlugin(registrar: Registrar) : MethodCallHandler {
val message = call.argument<String?>("message") val message = call.argument<String?>("message")
val recipients = call.argument<String?>("recipients") val recipients = call.argument<String?>("recipients")
sendSMS(result, recipients, message!!) sendSMS(result, recipients, message!!)
result.success("SMS Sent!")
} }
call.method == "canSendSMS" -> result.success(canSendSMS()) "canSendSMS" -> result.success(canSendSMS())
else -> result.notImplemented() else -> result.notImplemented()
} }
} }
@ -59,9 +91,8 @@ class FlutterSmsPlugin(registrar: Registrar) : MethodCallHandler {
return false return false
val intent = Intent(Intent.ACTION_SENDTO) val intent = Intent(Intent.ACTION_SENDTO)
intent.data = Uri.parse("smsto:") intent.data = Uri.parse("smsto:")
val activityInfo = intent.resolveActivityInfo(activity!!.packageManager, intent.flags) val activityInfo = intent.resolveActivityInfo(activity!!.packageManager, intent.flags.toInt())
return !(activityInfo == null || !activityInfo.exported) return !(activityInfo == null || !activityInfo.exported)
} }
private fun sendSMS(result: Result, phones: String?, message: String?) { private fun sendSMS(result: Result, phones: String?, message: String?) {
@ -69,16 +100,7 @@ class FlutterSmsPlugin(registrar: Registrar) : MethodCallHandler {
intent.data = Uri.parse("smsto:$phones") intent.data = Uri.parse("smsto:$phones")
intent.putExtra("sms_body", message) intent.putExtra("sms_body", message)
intent.putExtra(Intent.EXTRA_TEXT, message) intent.putExtra(Intent.EXTRA_TEXT, message)
// intent.putExtra(Intent.EXTRA_STREAM, attachment);
activity?.startActivityForResult(intent, REQUEST_CODE_SEND_SMS) activity?.startActivityForResult(intent, REQUEST_CODE_SEND_SMS)
result.success("SMS Sent!")
} }
// override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent): Boolean {
// if (requestCode == REQUEST_CODE_SEND_SMS && this.result != null) {
// this.result!!.success("finished")
// this.result = null
// return true
// }
// return false
// }
} }

View File

@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_sms","path":"/Users/rodydavis/Developer/GitHub/plugins/packages/flutter_sms/","dependencies":["url_launcher"]},{"name":"url_launcher","path":"/usr/local/Caskroom/flutter/1.2.1/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-6.0.3/","dependencies":[]}],"android":[{"name":"flutter_sms","path":"/Users/rodydavis/Developer/GitHub/plugins/packages/flutter_sms/","dependencies":["url_launcher"]},{"name":"url_launcher","path":"/usr/local/Caskroom/flutter/1.2.1/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-6.0.3/","dependencies":[]}],"macos":[{"name":"url_launcher_macos","path":"/usr/local/Caskroom/flutter/1.2.1/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-2.0.0/","dependencies":[]}],"linux":[{"name":"url_launcher_linux","path":"/usr/local/Caskroom/flutter/1.2.1/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_linux-2.0.0/","dependencies":[]}],"windows":[{"name":"url_launcher_windows","path":"/usr/local/Caskroom/flutter/1.2.1/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_windows-2.0.0/","dependencies":[]}],"web":[{"name":"flutter_sms","path":"/Users/rodydavis/Developer/GitHub/plugins/packages/flutter_sms/","dependencies":[]},{"name":"url_launcher_web","path":"/usr/local/Caskroom/flutter/1.2.1/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_web-2.0.0/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_sms","dependencies":["url_launcher"]},{"name":"url_launcher","dependencies":["url_launcher_linux","url_launcher_macos","url_launcher_windows","url_launcher_web"]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]},{"name":"url_launcher_windows","dependencies":[]}],"date_created":"2021-04-05 14:34:03.212116","version":"2.1.0-13.0.pre.206"} {"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_sms","path":"/Users/andrewcoutts/Projects/flutter_sms/","dependencies":["url_launcher"]},{"name":"url_launcher","path":"/Users/andrewcoutts/.pub-cache/hosted/pub.dartlang.org/url_launcher-6.0.9/","dependencies":[]}],"android":[{"name":"flutter_sms","path":"/Users/andrewcoutts/Projects/flutter_sms/","dependencies":["url_launcher"]},{"name":"url_launcher","path":"/Users/andrewcoutts/.pub-cache/hosted/pub.dartlang.org/url_launcher-6.0.9/","dependencies":[]}],"macos":[{"name":"url_launcher_macos","path":"/Users/andrewcoutts/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-2.0.1/","dependencies":[]}],"linux":[{"name":"url_launcher_linux","path":"/Users/andrewcoutts/.pub-cache/hosted/pub.dartlang.org/url_launcher_linux-2.0.1/","dependencies":[]}],"windows":[{"name":"url_launcher_windows","path":"/Users/andrewcoutts/.pub-cache/hosted/pub.dartlang.org/url_launcher_windows-2.0.1/","dependencies":[]}],"web":[{"name":"flutter_sms","path":"/Users/andrewcoutts/Projects/flutter_sms/","dependencies":[]},{"name":"url_launcher_web","path":"/Users/andrewcoutts/.pub-cache/hosted/pub.dartlang.org/url_launcher_web-2.0.2/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_sms","dependencies":["url_launcher"]},{"name":"url_launcher","dependencies":["url_launcher_linux","url_launcher_macos","url_launcher_web","url_launcher_windows"]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]},{"name":"url_launcher_windows","dependencies":[]}],"date_created":"2021-08-13 16:31:57.080699","version":"2.5.0-6.0.pre"}

View File

@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android { android {
compileSdkVersion 28 compileSdkVersion 31
sourceSets { sourceSets {
main.java.srcDirs += 'src/main/kotlin' 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). // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.example" applicationId "com.example.example"
minSdkVersion 16 minSdkVersion 16
targetSdkVersion 28 targetSdkVersion 31
versionCode flutterVersionCode.toInteger() versionCode flutterVersionCode.toInteger()
versionName flutterVersionName versionName flutterVersionName
} }

View File

@ -6,7 +6,7 @@ buildscript {
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.5.0' classpath 'com.android.tools.build:gradle:3.5.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
} }
} }

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

View File

@ -1,13 +1,12 @@
name: flutter_sms name: flutter_sms
description: A Flutter plugin to Send SMS and MMS on iOS and Android. If iMessage is enabled it will send as iMessage on iOS. This plugin must be tested on a real device on iOS. description: A Flutter plugin to Send SMS and MMS on iOS and Android. If iMessage is enabled it will send as iMessage on iOS. This plugin must be tested on a real device on iOS.
version: 2.3.1 version: 2.3.2
author: Rody Davis <rody.davis.jr@gmail.com>
homepage: https://github.com/rodydavis/plugins homepage: https://github.com/rodydavis/plugins
repository: https://github.com/fluttercommunity/flutter_sms repository: https://github.com/fluttercommunity/flutter_sms
maintainer: Rody Davis (@rodydavis) maintainer: Rody Davis (@rodydavis)
environment: environment:
sdk: ">=2.12.0-259.8.beta <3.0.0" sdk: ">=2.12.0 <3.0.0"
flutter: ^1.10.0 flutter: ^1.10.0
dependencies: dependencies: