Je reçois une erreur lorsque je souhaite accéder à un contact spécifique.Erreur lors de la recherche d'un contact Android
java.lang.IllegalArgumentException: colonne non valide contact_id
Voici l'exemple de code:
String number = "0877777777";
Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
String[] projection = new String[]{ ContactsContract.PhoneLookup.CONTACT_ID };
Cursor cur = getActivity().getContentResolver().query(uri, projection, null, null, null);
// if other contacts have that phone as well, we simply take the first contact found.
if (cur != null && cur.moveToNext()) {
Long id = cur.getLong(0);
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri contactUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(id));
intent.setData(contactUri);
startActivity(intent);
cur.close();
}
L'erreur est dans la projection, mais je ne sais pas comment y remédier. Le numéro est enregistré sur le téléphone testé. Un conseil pour résoudre le problème serait très apprécié.
De la [docs] (https://developer.android.com/reference/android/provider/ContactsContract.PhoneLookup.html) 'ContactsContract.PhoneLookup' contient seulement 3 colonnes. Aucun Contact_id là. Pour utiliser cette colonne, vous devez vous joindre à des contacts –