Android get contact number using name

前端 未结 3 1296
既然无缘
既然无缘 2021-01-16 16:41

I am trying to make an application on android that takes the contact name as a string input and returns his phone number if that contact exists in the phone book...

3条回答
  •  無奈伤痛
    2021-01-16 17:40

    Try this way...

    Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,);
    String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
    if(name.equals(Your_String)) {
        Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { id }, null);
        String lname = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
    }
    

提交回复
热议问题