![](/img/trans.png)
[英]Google Dialer crash at Nexus 4 (4.4.2) when I add custom contact
[英]Different results when add new contact on Google devices (Nexus 6, Pixel )
Nexus 6(Android 7.0)出现了一个奇怪的问题,即通过Intent添加新联系人时,Uri作为rawContacts的结果不是像往常一样查找。
这是我的意图:
public static Intent getNewContactIntent() {
Intent intent = new Intent(Intent.ACTION_INSERT, ContactsContract.Contacts.CONTENT_URI);
intent.putExtra("finishActivityOnSaveCompleted", true);
return intent;
}
结果onActivityResult:
Uri contactUri = data.getData();
在Nexus 6(Api 24)设备上:
内容://com.android.contacts/raw_contacts/1376
在其他设备(包括模拟器上的Nexus 6)上时:
内容://com.android.contacts/contacts/lookup/2883i3c5a4b238cc57aad/1376
如何在包括Google在内的所有Android设备上获得相同的结果?
额外信息:
这种怪异的行为也可以在Pixel(Android 8)上重现。
使用uri( ... / raw_contacts / 1376 )检索的数据:
+-----------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
| column | value |
+-----------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
| sort_key | Maher1 |
| send_to_voicemail | 0 |
| pinned | 0 |
| display_name | Maher1 |
| metadata_dirty | 0 |
| phonebook_label_alt | M |
| phonebook_bucket | 13 |
| version | 7 |
| custom_ringtone | null |
| _id | 1376 |
| times_contacted | 0 |
| account_type_and_data_set | com.google |
| sync4 | null |
| dirty | 0 |
| sync2 | Rn48fTVSLi17ImA9XBZXEUUJQwI."" |
| contact_id | 1376 |
| raw_contact_is_user_profile | 0 |
| aggregation_mode | 0 |
| data_set | null |
| phonebook_label | M |
| account_type | com.google |
| sync3 | 2017-08-31T12:44:27.075Z |
| display_name_alt | Maher1 |
| phonetic_name | null |
| last_time_contacted | null |
| display_name_source | 40 |
| backup_id | 3c5a4b238cc57aad |
| phonebook_bucket_alt | 13 |
| sort_key_alt | Maher1 |
| starred | 0 |
| deleted | 0 |
| account_name | maher*********@gmail.com |
| sourceid | 3c5a4b238cc57aad |
| sync1 | https://www.google.com/m8/feeds/contacts/maher*********%40gmail.com/base2_property-android_linksto-gprofiles_highresphotos/3c5a4b238cc57aad |
| phonetic_name_style | 0 |
+-----------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
虽然可以使用预期的uri检索数据( ... / contacts / lookup / 2883i3c5a4b238cc57aad / 1376 ):
+--------------------------------+-----------------------+
| column | value |
+--------------------------------+-----------------------+
| sort_key | Maher1 |
| photo_uri | null |
| send_to_voicemail | 0 |
| contact_status | null |
| contact_status_label | null |
| pinned | 0 |
| display_name | Maher1 |
| phonebook_label_alt | M |
| phonebook_bucket | 13 |
| contact_status_res_package | null |
| in_default_directory | 1 |
| photo_id | null |
| custom_ringtone | null |
| _id | 1376 |
| times_contacted | 0 |
| phonebook_label | M |
| lookup | 2883i3c5a4b238cc57aad |
| display_name_alt | Maher1 |
| phonetic_name | null |
| last_time_contacted | 0 |
| contact_last_updated_timestamp | 1504183466085 |
| has_phone_number | 0 |
| in_visible_group | 1 |
| photo_file_id | null |
| display_name_source | 40 |
| is_user_profile | 0 |
| contact_status_ts | null |
| sort_key_alt | Maher1 |
| phonebook_bucket_alt | 13 |
| contact_presence | null |
| starred | 0 |
| photo_thumb_uri | null |
| contact_status_icon | null |
| contact_chat_capability | null |
| name_raw_contact_id | 1376 |
| phonetic_name_style | 0 |
+--------------------------------+-----------------------+
我发现的最佳解决方案:
public static Uri getLookupURI(Intent data, ContentResolver resolver) {
Uri contactData = data.getData();
if (isRawContactsUri(contactData)) {
contactData = ContactsContract.RawContacts.getContactLookupUri(resolver, contactData);
}
return contactData;
}
public static boolean isRawContactsUri(Uri contactUri) {
return null != contactUri.getPathSegments() && !contactUri.getPathSegments().isEmpty() && "raw_contacts".equals(contactUri.getPathSegments().get(0));
}
检查结果是否包含带有rawContacts的uri,然后提取LookupUri。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.