i have working with small android application in this application i am try to get contact which used whats app application and also alert for my selected whats app contact from my application when contact updates his/her profile picture and status.
Asked
Active
Viewed 5,335 times
2 Answers
8
You can query your content cursor to see what properties contacts have.
Cursor c1 = appActivity.getContentResolver().query(
ContactsContract.Data.CONTENT_URI
,null,null,null, null);
c1.moveToFirst();
DatabaseUtils.dumpCursor(c1);
c1.close();
Or specifically if you want to query for whatsapp contacts here are the properties:
- You can query for
ContactsContract.RawContacts.ACCOUNT_TYPE
with value com.whatsapp - You can use
MIMETYPE
with value vnd.android.cursor.item/vnd.com.whatsapp.profile
Example:
c = appActivity.getContentResolver().query(
ContactsContract.Data.CONTENT_URI
,new String[] { ContactsContract.Contacts.Data._ID }
,"mimetype=?",
new String[] { "vnd.android.cursor.item/vnd.com.whatsapp.profile" }, null);
c1.moveToFirst();
DatabaseUtils.dumpCursor(c1);
c1.close();
Note (@Ragnar): MIMETYPE
column didn't work for me. I used ACCOUNT_TYPE
column and it worked.

Simon Dorociak
- 33,374
- 10
- 68
- 106

user303730
- 384
- 1
- 5
- 15
-
1`ACCOUNT_TYPE` column worked for me. You saved my day. Thank you. – Simon Dorociak Dec 23 '15 at 00:30
-
@Simon Account_Type column's value is not same on all devices – Zaid Mirza Sep 16 '17 at 15:49
1
If you wish read Telegram contacts:
private val tgContactMimeType = "vnd.android.cursor.item/vnd.org.telegram.messenger.android.profile";
private val projectionTelegram = arrayOf(
ContactsContract.Data.DATA1,//userId
ContactsContract.Data.DATA3,//userPhone
ContactsContract.Data.DISPLAY_NAME)//displayName
//read telegram contacts
phoneCursor = cr.query(
ContactsContract.Data.CONTENT_URI,
projectionTelegram,
ContactsContract.Data.MIMETYPE + " = '" + tgContactMimeType + "'",
null,
null)
if (phoneCursor != null) {
while (phoneCursor.moveToNext()) {
val userId = phoneCursor.getString(0)
val number = phoneCursor.getString(1)
val displayname = phoneCursor.getString(2)
val contact = PhoneContact()
contact.firstName = displayname
contact.phones.add(number)
contactsMap[userId.toString()] = contact
}
}

nAkhmedov
- 3,522
- 4
- 37
- 72