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.content.pm.PackageManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
|
||||||
class FlutterSmsPlugin : MethodCallHandler, ActivityResultListener {
|
class FlutterSmsPlugin(registrar: Registrar) : MethodCallHandler, ActivityResultListener {
|
||||||
private val REQUEST_CODE_SEND_SMS = 205
|
private val REQUEST_CODE_SEND_SMS = 205
|
||||||
|
|
||||||
var activity: Activity? = null
|
var activity: Activity? = null
|
||||||
@ -27,13 +27,15 @@ class FlutterSmsPlugin : MethodCallHandler, ActivityResultListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(registrar: Registrar) {
|
init {
|
||||||
this.activity = registrar.activity()
|
this.activity = registrar.activity()
|
||||||
registrar.addActivityResultListener(this)
|
registrar.addActivityResultListener(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMethodCall(call: MethodCall, result: Result) {
|
override fun onMethodCall(call: MethodCall, result: Result) {
|
||||||
if (call.method.equals("sendSMS")) {
|
this.result = result
|
||||||
|
when {
|
||||||
|
call.method == "sendSMS" -> {
|
||||||
if (!canSendSMS()) {
|
if (!canSendSMS()) {
|
||||||
result.error(
|
result.error(
|
||||||
"device_not_capable",
|
"device_not_capable",
|
||||||
@ -41,15 +43,13 @@ class FlutterSmsPlugin : MethodCallHandler, ActivityResultListener {
|
|||||||
"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.")
|
"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
|
return
|
||||||
}
|
}
|
||||||
|
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!");
|
result.success("SMS Sent!")
|
||||||
} else if (call.method == "canSendSMS") {
|
}
|
||||||
result.success(canSendSMS())
|
call.method == "canSendSMS" -> result.success(canSendSMS())
|
||||||
} else {
|
else -> result.notImplemented()
|
||||||
result.notImplemented()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +57,6 @@ class FlutterSmsPlugin : MethodCallHandler, ActivityResultListener {
|
|||||||
private fun canSendSMS(): Boolean {
|
private fun canSendSMS(): Boolean {
|
||||||
if (!activity!!.packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY))
|
if (!activity!!.packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY))
|
||||||
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)
|
||||||
@ -66,19 +65,18 @@ class FlutterSmsPlugin : MethodCallHandler, ActivityResultListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun sendSMS(result: Result, phones: String?, message: String?) {
|
private fun sendSMS(result: Result, phones: String?, message: String?) {
|
||||||
this.result = result
|
|
||||||
val intent = Intent(Intent.ACTION_SENDTO)
|
val intent = Intent(Intent.ACTION_SENDTO)
|
||||||
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);
|
// 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 {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent): Boolean {
|
||||||
if (requestCode == REQUEST_CODE_SEND_SMS && result != null) {
|
if (requestCode == REQUEST_CODE_SEND_SMS && this.result != null) {
|
||||||
result!!.success("finished")
|
this.result!!.success("finished")
|
||||||
result = null
|
this.result = null
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -11,6 +11,10 @@
|
|||||||
<excludeFolder url="file://$MODULE_DIR$/example/.dart_tool" />
|
<excludeFolder url="file://$MODULE_DIR$/example/.dart_tool" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/example/.pub" />
|
<excludeFolder url="file://$MODULE_DIR$/example/.pub" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/example/build" />
|
<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>
|
</content>
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="Dart SDK" level="project" />
|
<orderEntry type="library" name="Dart SDK" level="project" />
|
||||||
|
Loading…
Reference in New Issue
Block a user