Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid query phonenumber to obtain rawcontactID
    primarykey
    data
    text
    <p>I would like to query on phonenumber to obtain the rawcontactID.</p> <p>The only thing I know of the contact is the given phonenumber, but for my function I need to have the rawcontactID. I got a working code but now I did use 2 seperate queries. What I would like to have is 1 query that can do both just to save some query time.</p> <p>my code:</p> <pre><code> Uri uri = Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, Uri.encode(phoneNumber)); String[] columns = new String[]{Phone.CONTACT_ID, Phone.DISPLAY_NAME, Phone.NUMBER, Phone._ID }; Cursor cursor = contentResolver.query(uri, columns, null, null, null); if(cursor!=null) { int clenght = cursor.getCount(); while(cursor.moveToNext()){ //contactName = cursor.getString(cursor.getColumnIndexOrThrow(PhoneLookup.DISPLAY_NAME)); id = cursor.getString(cursor.getColumnIndex(Phone.CONTACT_ID)); } cursor.close(); } Cursor pCur = contentResolver.query(ContactsContract.Data.CONTENT_URI, new String[]{ContactsContract.Data.RAW_CONTACT_ID}, ContactsContract.Data.CONTACT_ID+" = "+ id, null, null); if(pCur!=null) { int clenght = pCur.getCount(); while(pCur.moveToNext()){ //contactName = cursor.getString(cursor.getColumnIndexOrThrow(PhoneLookup.DISPLAY_NAME)); id = pCur.getString(pCur.getColumnIndex(ContactsContract.Data.RAW_CONTACT_ID)); } pCur.close(); } </code></pre> <p>thanks in advance</p> <p>Edit:</p> <p>My code above works fine, but I am still looking for increasing speed for large number of contacts. Therefore I will give a bounty if someone comes with a solution to combine my queries.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload