mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
add some more third party intent handling
This commit is contained in:
parent
f2f22a34ff
commit
29c16d543f
@ -94,6 +94,15 @@
|
|||||||
<data android:mimeType="vnd.android.cursor.item/group"/>
|
<data android:mimeType="vnd.android.cursor.item/group"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
|
<intent-filter android:label="@string/edit_contact">
|
||||||
|
<action android:name="android.intent.action.VIEW"/>
|
||||||
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
|
|
||||||
|
<data android:mimeType="vnd.android.cursor.item/person"/>
|
||||||
|
<data android:mimeType="vnd.android.cursor.item/contact"/>
|
||||||
|
<data android:mimeType="vnd.android.cursor.item/raw_contact"/>
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.EDIT"/>
|
<action android:name="android.intent.action.EDIT"/>
|
||||||
<category android:name="android.intent.category.DEFAULT"/>
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
|
@ -95,10 +95,16 @@ class ContactActivity : SimpleActivity() {
|
|||||||
|
|
||||||
private fun initContact() {
|
private fun initContact() {
|
||||||
var contactId = intent.getIntExtra(CONTACT_ID, 0)
|
var contactId = intent.getIntExtra(CONTACT_ID, 0)
|
||||||
if (contactId == 0 && intent.action == ContactsContract.QuickContact.ACTION_QUICK_CONTACT) {
|
val action = intent.action
|
||||||
|
if (contactId == 0 && (action == ContactsContract.QuickContact.ACTION_QUICK_CONTACT || action == Intent.ACTION_VIEW)) {
|
||||||
val data = intent.data
|
val data = intent.data
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
val rawId = getContactRawId(data) ?: -1
|
val rawId = if (data.path.contains("lookup")) {
|
||||||
|
getLookupUriRawId(data)
|
||||||
|
} else {
|
||||||
|
getContactUriRawId(data)
|
||||||
|
}
|
||||||
|
|
||||||
if (rawId != -1) {
|
if (rawId != -1) {
|
||||||
contactId = rawId
|
contactId = rawId
|
||||||
}
|
}
|
||||||
|
@ -48,20 +48,26 @@ fun Context.sendSMSIntent(recipient: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||||
fun Context.getContactRawId(dataUri: Uri): Int? {
|
fun Context.getLookupUriRawId(dataUri: Uri): Int {
|
||||||
val lookupKey = getLookupKeyFromUri(dataUri)
|
val lookupKey = getLookupKeyFromUri(dataUri)
|
||||||
if (lookupKey != null && isLollipopPlus()) {
|
if (lookupKey != null && isLollipopPlus()) {
|
||||||
val uri = lookupContactUri(lookupKey, this)
|
val uri = lookupContactUri(lookupKey, this)
|
||||||
val projection = arrayOf(ContactsContract.Contacts.NAME_RAW_CONTACT_ID)
|
return getContactUriRawId(uri)
|
||||||
var cursor: Cursor? = null
|
}
|
||||||
try {
|
return -1
|
||||||
cursor = contentResolver.query(uri, projection, null, null, null)
|
}
|
||||||
if (cursor.moveToFirst()) {
|
|
||||||
return cursor.getIntValue(ContactsContract.Contacts.NAME_RAW_CONTACT_ID)
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||||
}
|
fun Context.getContactUriRawId(uri: Uri): Int {
|
||||||
} finally {
|
val projection = arrayOf(ContactsContract.Contacts.NAME_RAW_CONTACT_ID)
|
||||||
cursor?.close()
|
var cursor: Cursor? = null
|
||||||
|
try {
|
||||||
|
cursor = contentResolver.query(uri, projection, null, null, null)
|
||||||
|
if (cursor.moveToFirst()) {
|
||||||
|
return cursor.getIntValue(ContactsContract.Contacts.NAME_RAW_CONTACT_ID)
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
cursor?.close()
|
||||||
}
|
}
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user