如何在我的应用中检索微信联系人列表?

时间:2018-06-26 11:46:09

标签: java android wechat

我正在尝试访问我的Android应用程序中的所有微信联系人,如果用户点击它,则在微信上打开带有该联系人的聊天页面。我阅读了Here的官方文档,但没有帮助。我在其他任何地方也找不到任何有用的答案。在我的代码中,我按MIME类型过滤联系人,但每次都得到一个空字符串。请帮我解决...

//MIMETYPE of WeCha
        String mimeString = "vnd.android.cursor.item/vnd.com.tencent.mm.chatting.voip.video";

        String displayName = null;
        String phone = null;
        Long _id;
        ContentResolver resolver = getApplicationContext().getContentResolver();
        //Sorting contacts Alphabetically
        Cursor cursor = resolver.query(ContactsContract.Data.CONTENT_URI, null, null, null, ContactsContract.Contacts.DISPLAY_NAME);
        while (cursor.moveToNext()) {

            _id = cursor.getLong(cursor.getColumnIndex(ContactsContract.Data._ID));

            phone = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

            displayName = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
            //Getting the MimeType of user
            String mimeType = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.MIMETYPE));
If(mimeType==mimeString)
{

            //Logs for debugging
            Log.d("Look here", _id.toString());
            Log.d("Look here", displayName);
            Log.d("Look here", mimeType);
}
      }
        cursor.close();

0 个答案:

没有答案