1. Are you ready for the Galaxy S20? Here is everything we know so far!

Contacts NOT on Whatsapp - Android

Discussion in 'Android Development' started by elmousa68, Jul 18, 2021.

  1. elmousa68

    elmousa68 Lurker
    Thread Starter

    In the following code fragment, a contact list is retrieved which has the ACCOUNT_TYPE="com.whatsapp".

    Cursor c = getContentResolver().query(
    ContactsContract.RawContacts.CONTENT_URI,
    new String[]{ContactsContract.RawContacts.CONTACT_ID,
    ContactsContract.RawContacts.DISPLAY_NAME_PRIMARY},
    ContactsContract.RawContacts.ACCOUNT_TYPE + "= ?",
    new String[]{"com.whatsapp"},
    "display_name ASC");

    From experimenting with code, I have found that ACCOUNT_TYPE can be several things at once. eg. it can be equal to "com.whatsapp" and "com.google".

    When I run a the method c.getCount() on the above cursor, I get 956 contacts. While the same command returns 1305 for "com.google", which is the total number of contacts on the device. All of the contacts are Google contacts while 956 of them are Whatsapp contacts.

    I am trying to get the contacts on the device which are NOT Whatsapp contacts. I tried the following:

    Cursor c = getContentResolver().query(
    ContactsContract.RawContacts.CONTENT_URI,
    new String[]{ContactsContract.RawContacts.CONTACT_ID,
    ContactsContract.RawContacts.DISPLAY_NAME_PRIMARY},
    ContactsContract.RawContacts.ACCOUNT_TYPE + "!= ?",
    new String[]{"com.whatsapp"},
    "display_name ASC");

    Note : != instead of =

    This did NOT work.

    I tried:

    Cursor c = getContentResolver().query(
    ContactsContract.RawContacts.CONTENT_URI,
    new String[]{ContactsContract.RawContacts.CONTACT_ID,
    ContactsContract.RawContacts.DISPLAY_NAME_PRIMARY},
    ContactsContract.RawContacts.ACCOUNT_TYPE + "!= ? and " +
    ContactsContract.RawContacts.ACCOUNT_TYPE + "= ?",
    new String[]{"com.whatsapp,"com.google"},
    "display_name ASC");
    This did not work either.

    Please help..

    How can I get a list of contact which are NOT on a specific account type (e.g. Whatsapp)?

    Muchos Gracias. Danke. :)
     



    1. Download the Forums for Android™ app!


      Download

       
  2. Askautmir

    Askautmir Lurker

    I'm not really sure about this, but I think you need to create a second Cursor to filter the different types of accounts within the Cursor you made.

    I think this is because the contacts in the address book can have different types: com.google is the base for everyone, but then they can have the com.whatsapp type and maybe even the com.telegram type.

    That's why when you go to do the query and look for contacts that contain com.whatsapp a minority of them come up, since not all of them have that type as well, while if you look for those that are different from com.whatsapp they all come up, since all of them are at least com.google, including those that are not com.whatsapp.

    I wish I could help you more than that, but I'm still quite ignorant on the subject myself.
     
Loading...

Share This Page

Loading...