Android how to get contact list which used whats app application programmatically

匿名 (未验证) 提交于 2019-12-03 07:36:14

问题:

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.

回答1:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!