mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
fix #464, properly handle some new contact related intents
This commit is contained in:
@ -170,6 +170,12 @@
|
||||
<data android:mimeType="vnd.android.cursor.item/contact"/>
|
||||
<data android:mimeType="vnd.android.cursor.item/raw_contact"/>
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="com.android.contacts.action.SHOW_OR_CREATE_CONTACT"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<data android:scheme="mailto"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
|
@ -47,10 +47,26 @@ class InsertOrEditContactActivity : SimpleActivity() {
|
||||
updateTextColors(insert_edit_contact_holder)
|
||||
new_contact_tmb.setImageDrawable(resources.getColoredDrawableWithColor(R.drawable.ic_new_contact_vector, config.textColor))
|
||||
new_contact_holder.setOnClickListener {
|
||||
val name = intent.getStringExtra(KEY_NAME) ?: ""
|
||||
val phoneNumber = getPhoneNumberFromIntent(intent) ?: ""
|
||||
val email = getEmailFromIntent(intent) ?: ""
|
||||
|
||||
Intent().apply {
|
||||
action = Intent.ACTION_INSERT
|
||||
data = ContactsContract.Contacts.CONTENT_URI
|
||||
putExtra(KEY_PHONE, getPhoneNumberFromIntent(intent))
|
||||
|
||||
if (phoneNumber.isNotEmpty()) {
|
||||
putExtra(KEY_PHONE, phoneNumber)
|
||||
}
|
||||
|
||||
if (name.isNotEmpty()) {
|
||||
putExtra(KEY_NAME, name)
|
||||
}
|
||||
|
||||
if (email.isNotEmpty()) {
|
||||
putExtra(KEY_EMAIL, email)
|
||||
}
|
||||
|
||||
if (resolveActivity(packageManager) != null) {
|
||||
startActivityForResult(this, START_INSERT_ACTIVITY)
|
||||
} else {
|
||||
@ -65,10 +81,21 @@ class InsertOrEditContactActivity : SimpleActivity() {
|
||||
private fun gotContacts(contacts: ArrayList<Contact>) {
|
||||
ContactsAdapter(this, contacts, null, LOCATION_INSERT_OR_EDIT, null, existing_contact_list, existing_contact_fastscroller) {
|
||||
val contact = it as Contact
|
||||
val phoneNumber = getPhoneNumberFromIntent(intent) ?: ""
|
||||
val email = getEmailFromIntent(intent) ?: ""
|
||||
|
||||
Intent(applicationContext, EditContactActivity::class.java).apply {
|
||||
data = getContactPublicUri(contact)
|
||||
action = ADD_NEW_CONTACT_NUMBER
|
||||
putExtra(KEY_PHONE, getPhoneNumberFromIntent(intent))
|
||||
|
||||
if (phoneNumber.isNotEmpty()) {
|
||||
putExtra(KEY_PHONE, phoneNumber)
|
||||
}
|
||||
|
||||
if (email.isNotEmpty()) {
|
||||
putExtra(KEY_EMAIL, email)
|
||||
}
|
||||
|
||||
putExtra(IS_PRIVATE, contact.isPrivate())
|
||||
startActivityForResult(this, START_EDIT_ACTIVITY)
|
||||
}
|
||||
|
@ -3,11 +3,13 @@ package com.simplemobiletools.contacts.pro.activities
|
||||
import android.annotation.TargetApi
|
||||
import android.content.ContentValues
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.telecom.TelecomManager
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.contacts.pro.R
|
||||
import com.simplemobiletools.contacts.pro.helpers.KEY_MAILTO
|
||||
import com.simplemobiletools.contacts.pro.helpers.KEY_PHONE
|
||||
import com.simplemobiletools.contacts.pro.helpers.REQUEST_CODE_SET_DEFAULT_DIALER
|
||||
|
||||
@ -53,6 +55,14 @@ open class SimpleActivity : BaseSimpleActivity() {
|
||||
return null
|
||||
}
|
||||
|
||||
protected fun getEmailFromIntent(intent: Intent): String? {
|
||||
return if (intent.dataString?.startsWith("$KEY_MAILTO:") == true) {
|
||||
Uri.decode(intent.dataString!!.substringAfter("$KEY_MAILTO:").trim())
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.M)
|
||||
protected fun launchSetDefaultDialerIntent() {
|
||||
Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER).putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME, packageName).apply {
|
||||
|
@ -66,7 +66,7 @@ fun Context.editContact(contact: Contact) {
|
||||
|
||||
fun Context.sendEmailIntent(recipient: String) {
|
||||
Intent(Intent.ACTION_SENDTO).apply {
|
||||
data = Uri.fromParts("mailto", recipient, null)
|
||||
data = Uri.fromParts(KEY_MAILTO, recipient, null)
|
||||
if (resolveActivity(packageManager) != null) {
|
||||
startActivity(this)
|
||||
} else {
|
||||
|
@ -31,6 +31,7 @@ const val REQUEST_CODE_SET_DEFAULT_DIALER = 1
|
||||
const val KEY_PHONE = "phone"
|
||||
const val KEY_NAME = "name"
|
||||
const val KEY_EMAIL = "email"
|
||||
const val KEY_MAILTO = "mailto"
|
||||
|
||||
const val LOCATION_CONTACTS_TAB = 0
|
||||
const val LOCATION_FAVORITES_TAB = 1
|
||||
|
Reference in New Issue
Block a user