updating project
This commit is contained in:
parent
eb75a603e0
commit
16a02e9cf2
Binary file not shown.
@ -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<String>("message")
|
||||
val recipients = call.argument<String>("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<String?>("message")
|
||||
val recipients = call.argument<String?>("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
|
||||
|
@ -11,6 +11,10 @@
|
||||
<excludeFolder url="file://$MODULE_DIR$/example/.dart_tool" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/example/.pub" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/example/build" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/flutter_sms/example/.dart_tool" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/flutter_sms/example/.pub" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/flutter_sms/example/build" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/example/ios/Flutter/App.framework/flutter_assets/packages" />
|
||||
</content>
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Dart SDK" level="project" />
|
||||
|
Loading…
Reference in New Issue
Block a user