handle send SMS intent

This commit is contained in:
tibbi 2017-12-11 20:39:28 +01:00
parent 829897b5e1
commit 20bd9cf01c
2 changed files with 20 additions and 5 deletions

View File

@ -18,7 +18,8 @@ import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CONTACTS import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CONTACTS
import com.simplemobiletools.contacts.R import com.simplemobiletools.contacts.R
import com.simplemobiletools.contacts.extensions.config import com.simplemobiletools.contacts.extensions.config
import com.simplemobiletools.contacts.extensions.sendEmail import com.simplemobiletools.contacts.extensions.sendEmailIntent
import com.simplemobiletools.contacts.extensions.sendSMSIntent
import com.simplemobiletools.contacts.helpers.CONTACT_ID import com.simplemobiletools.contacts.helpers.CONTACT_ID
import com.simplemobiletools.contacts.helpers.ContactsHelper import com.simplemobiletools.contacts.helpers.ContactsHelper
import com.simplemobiletools.contacts.models.Contact import com.simplemobiletools.contacts.models.Contact
@ -94,10 +95,12 @@ class ContactActivity : SimpleActivity() {
contact_email_image.applyColorFilter(textColor) contact_email_image.applyColorFilter(textColor)
contact_photo.setOnClickListener { } contact_photo.setOnClickListener { }
contact_send_sms.setOnClickListener { } contact_send_sms.setOnClickListener {
sendSMSIntent(contact!!.number)
}
contact_start_call.setOnClickListener { } contact_start_call.setOnClickListener { }
contact_send_email.setOnClickListener { contact_send_email.setOnClickListener {
sendEmail(contact!!.email) sendEmailIntent(contact!!.email)
} }
updateTextColors(contact_scrollview) updateTextColors(contact_scrollview)

View File

@ -9,8 +9,20 @@ import com.simplemobiletools.contacts.helpers.Config
val Context.config: Config get() = Config.newInstance(applicationContext) val Context.config: Config get() = Config.newInstance(applicationContext)
fun Context.sendEmail(recipient: String) { fun Context.sendEmailIntent(recipient: String) {
Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", recipient, null)).apply { Intent(Intent.ACTION_SENDTO).apply {
data = Uri.fromParts("mailto", recipient, null)
if (resolveActivity(packageManager) != null) {
startActivity(this)
} else {
toast(R.string.no_app_found)
}
}
}
fun Context.sendSMSIntent(recipient: String) {
Intent(Intent.ACTION_SENDTO).apply {
data = Uri.fromParts("smsto", recipient, null)
if (resolveActivity(packageManager) != null) { if (resolveActivity(packageManager) != null) {
startActivity(this) startActivity(this)
} else { } else {