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.
user303730
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.
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
}
}
来源:https://stackoverflow.com/questions/24227356/android-how-to-get-contact-list-which-used-whats-app-application-programmaticall