En la aplicación Contactos, el primero que muestra es del propietario.
¿Se puede extraer la información del contacto del propietario del dispositivo?
He buscado por todos los contactos disponibles del proveedor ContactsContract.Contacts
y no veo en ningún caso que lo indexe.
¿Me pregunto, si se guarda en otro rincón o bien es de solo uso interno de la app contactos del sistema?
Edición
Busancdo por el SDK he econtrado como obtener los datos del propietario del dispositivo
public static SimpleContact TESTgetLocalProfile(Context context) {
Uri PROFILE_URI = ContactsContract.Profile.CONTENT_URI;
String[] PROJECTION = new String[]{
ContactsContract.Profile._ID,
ContactsContract.Profile.DISPLAY_NAME,
ContactsContract.Profile.PHOTO_URI,
ContactsContract.Profile.HAS_PHONE_NUMBER,
ContactsContract.Profile.LOOKUP_KEY
};
final String SELECTION = ContactsContract.CommonDataKinds.Email.CONTACT_ID + "= ?";
String[] mSelectionArgs = {"10"};
String sortOrder = ContactsContract.CommonDataKinds.Email.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
// Build adapter with contact entries
Cursor c = context.getContentResolver().query(PROFILE_URI, PROJECTION, null, null, null);
SimpleContact item = null;
if (c != null && c.moveToFirst()) {
String contactId = c.getString(c.getColumnIndex(ContactsContract.Profile._ID));
item = new SimpleContact(contactId);
item.setDisplayName(c.getString(c.getColumnIndex(ContactsContract.Profile.DISPLAY_NAME)));
item.setPhoto(c.getString(c.getColumnIndex(ContactsContract.Profile.PHOTO_URI)));
item.setLookupKey(c.getString(c.getColumnIndex(ContactsContract.Profile.LOOKUP_KEY)));
if (c.getInt(c.getColumnIndex(ContactsContract.Profile.HAS_PHONE_NUMBER)) > 0) {
//No ser como obtener el número
}
c.close();
}
return item;
}
Debug de campos:
D/ContactsHelper: columName: sort_key =Test User
D/ContactsHelper: columName: blocked =0
D/ContactsHelper: columName: photo_uri =content://com.android.contacts/display_photo/9223372034707292161
D/ContactsHelper: columName: status_label =null
D/ContactsHelper: columName: status_ts =null
D/ContactsHelper: columName: status_res_package =null
D/ContactsHelper: columName: display_name =Test User
D/ContactsHelper: columName: last_time_used =null
D/ContactsHelper: columName: mimetype =vnd.android.cursor.item/name
D/ContactsHelper: columName: phonebook_label_alt =U
D/ContactsHelper: columName: data6 =null
D/ContactsHelper: columName: version =7
D/ContactsHelper: columName: photo_id =9223372034707292166
D/ContactsHelper: columName: data3 =User
D/ContactsHelper: columName: custom_ringtone =null
D/ContactsHelper: columName: times_contacted =0
D/ContactsHelper: columName: account_type_and_data_set =com.android.localphone
D/ContactsHelper: columName: dirty =1
D/ContactsHelper: columName: data7 =null
D/ContactsHelper: columName: data15 =null
D/ContactsHelper: columName: raw_contact_is_user_profile =1
D/ContactsHelper: columName: data_set =null
D/ContactsHelper: columName: phonebook_label =T
D/ContactsHelper: columName: data10 =1
D/ContactsHelper: columName: res_package =null
D/ContactsHelper: columName: account_type =com.android.localphone
D/ContactsHelper: columName: data11 =0
D/ContactsHelper: columName: display_name_alt =User, Test
D/ContactsHelper: columName: lookup =profile
D/ContactsHelper: columName: phonetic_name =null
D/ContactsHelper: columName: last_time_contacted =0
D/ContactsHelper: columName: contact_last_updated_timestamp =1505762023483
D/ContactsHelper: columName: data13 =null
D/ContactsHelper: columName: in_visible_group =0
D/ContactsHelper: columName: chat_capability =null
D/ContactsHelper: columName: data9 =null
D/ContactsHelper: columName: carrier_presence =0
D/ContactsHelper: columName: data_sync1 =null
D/ContactsHelper: columName: sort_key_alt =User, Test
D/ContactsHelper: columName: contact_presence =null
D/ContactsHelper: columName: data_version =0
D/ContactsHelper: columName: phonetic_name_style =0
D/ContactsHelper: columName: name_raw_contact_id =9223372034707292163
D/ContactsHelper: columName: raw_contact_id =9223372034707292163
D/ContactsHelper: columName: send_to_voicemail =0
D/ContactsHelper: columName: data4 =null
D/ContactsHelper: columName: data12 =null
D/ContactsHelper: columName: contact_status =null
D/ContactsHelper: columName: contact_status_label =null
D/ContactsHelper: columName: pinned =0
D/ContactsHelper: columName: status_icon =null
D/ContactsHelper: columName: status =null
D/ContactsHelper: columName: data1 =Test User
D/ContactsHelper: columName: phonebook_bucket =21
D/ContactsHelper: columName: data_sync2 =null
D/ContactsHelper: columName: contact_status_res_package =null
D/ContactsHelper: columName: in_default_directory =1
D/ContactsHelper: columName: _id =9223372034707292163
D/ContactsHelper: columName: hash_id =null
D/ContactsHelper: columName: is_super_primary =0
D/ContactsHelper: columName: data5 =null
D/ContactsHelper: columName: contact_id =9223372034707292162
D/ContactsHelper: columName: data8 =null
D/ContactsHelper: columName: is_primary =0
D/ContactsHelper: columName: data_sync4 =null
D/ContactsHelper: columName: has_phone_number =1
D/ContactsHelper: columName: display_name_source =40
D/ContactsHelper: columName: photo_file_id =9223372034707292161
D/ContactsHelper: columName: custom_vibration =0
D/ContactsHelper: columName: data_sync3 =null
D/ContactsHelper: columName: backup_id =null
D/ContactsHelper: columName: data14 =null
D/ContactsHelper: columName: contact_status_ts =null
D/ContactsHelper: columName: phonebook_bucket_alt =22
D/ContactsHelper: columName: mode =null
D/ContactsHelper: columName: data2 =Test
D/ContactsHelper: columName: group_sourceid =null
D/ContactsHelper: columName: starred =0
D/ContactsHelper: columName: photo_thumb_uri =content://com.android.contacts/contacts/9223372034707292162/photo
D/ContactsHelper: columName: times_used =null
D/ContactsHelper: columName: contact_status_icon =null
D/ContactsHelper: columName: contact_chat_capability =null
D/ContactsHelper: columName: account_name =PHONE
D/ContactsHelper: columName: sourceid =null
Lo que me falta es obtener el número de teléfono asociado, pero como que el contacto no está dentro del proveedor de contactos ni de rawcontacts, no lo puedo obtener.