From 16a02e9cf25bb7bc4b651a253908f6215b3703d6 Mon Sep 17 00:00:00 2001 From: Rody Davis Date: Mon, 28 Oct 2019 11:57:56 -0400 Subject: [PATCH] updating project --- android/.idea/caches/build_file_checksums.ser | Bin 494 -> 494 bytes .../example/flutter_sms/FlutterSmsPlugin.kt | 48 +++++++++--------- flutter_sms.iml | 4 ++ 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/android/.idea/caches/build_file_checksums.ser b/android/.idea/caches/build_file_checksums.ser index 20c85544fc5f847c9fcf3e0a9c45b2096474cbd1..113ee78d866c4ae42b40115926135b74fa97a1b8 100644 GIT binary patch delta 14 WcmaFI{Em6TOy<8PRU797F#-THT?SeJ delta 14 WcmaFI{Em6TOy+BiGdIo&Vgvv*wFaL6 diff --git a/android/src/main/kotlin/com/example/flutter_sms/FlutterSmsPlugin.kt b/android/src/main/kotlin/com/example/flutter_sms/FlutterSmsPlugin.kt index 558b086..2439a95 100644 --- a/android/src/main/kotlin/com/example/flutter_sms/FlutterSmsPlugin.kt +++ b/android/src/main/kotlin/com/example/flutter_sms/FlutterSmsPlugin.kt @@ -13,7 +13,7 @@ import android.content.Intent import android.content.pm.PackageManager import android.os.Build -class FlutterSmsPlugin : MethodCallHandler, ActivityResultListener { +class FlutterSmsPlugin(registrar: Registrar) : MethodCallHandler, ActivityResultListener { private val REQUEST_CODE_SEND_SMS = 205 var activity: Activity? = null @@ -27,29 +27,29 @@ class FlutterSmsPlugin : MethodCallHandler, ActivityResultListener { } } - constructor(registrar: Registrar) { + init { this.activity = registrar.activity() registrar.addActivityResultListener(this) } override fun onMethodCall(call: MethodCall, result: Result) { - if (call.method.equals("sendSMS")) { - if (!canSendSMS()) { - result.error( - "device_not_capable", - "The current device is not capable of sending text messages.", - "A device may be unable to send messages if it does not support messaging or if it is not currently configured to send messages. This only applies to the ability to send text messages via iMessage, SMS, and MMS.") - return - } - - val message = call.argument("message") - val recipients = call.argument("recipients") - sendSMS(result, recipients, message!!) - //result.success("SMS Sent!"); - } else if (call.method == "canSendSMS") { - result.success(canSendSMS()) - } else { - result.notImplemented() + this.result = result + when { + call.method == "sendSMS" -> { + if (!canSendSMS()) { + result.error( + "device_not_capable", + "The current device is not capable of sending text messages.", + "A device may be unable to send messages if it does not support messaging or if it is not currently configured to send messages. This only applies to the ability to send text messages via iMessage, SMS, and MMS.") + return + } + val message = call.argument("message") + val recipients = call.argument("recipients") + sendSMS(result, recipients, message!!) + result.success("SMS Sent!") + } + call.method == "canSendSMS" -> result.success(canSendSMS()) + else -> result.notImplemented() } } @@ -57,7 +57,6 @@ class FlutterSmsPlugin : MethodCallHandler, ActivityResultListener { private fun canSendSMS(): Boolean { if (!activity!!.packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) return false - val intent = Intent(Intent.ACTION_SENDTO) intent.data = Uri.parse("smsto:") val activityInfo = intent.resolveActivityInfo(activity!!.packageManager, intent.flags) @@ -66,19 +65,18 @@ class FlutterSmsPlugin : MethodCallHandler, ActivityResultListener { } private fun sendSMS(result: Result, phones: String?, message: String?) { - this.result = result val intent = Intent(Intent.ACTION_SENDTO) intent.data = Uri.parse("smsto:$phones") intent.putExtra("sms_body", 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) } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent): Boolean { - if (requestCode == REQUEST_CODE_SEND_SMS && result != null) { - result!!.success("finished") - result = null + if (requestCode == REQUEST_CODE_SEND_SMS && this.result != null) { + this.result!!.success("finished") + this.result = null return true } return false diff --git a/flutter_sms.iml b/flutter_sms.iml index 73e7ebd..4deb584 100644 --- a/flutter_sms.iml +++ b/flutter_sms.iml @@ -11,6 +11,10 @@ + + + +