如何检查是否在android手机簿中的联系人启用了WhatsApp的? [英] How to Check if a contact on android phone book has whatsapp enabled?

查看:239
本文介绍了如何检查是否在android手机簿中的联系人启用了WhatsApp的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关从我的通讯录给定的数字,我需要看行动如果数值WhatsApp的功能。 (这个想法是选择短信/ WhatsApp的发起文本意图)

For a given number from my address book, I need to look-up if the number has whatsapp enabled. (The idea is to choose SMS/WhatsApp for initiating a text intent)

可以说,我有两个号码下的接触,我需要知道哪一个使WhatsApp的。

Lets say, I have two numbers under a contact, And I need to know which one has whatsapp enabled.

上的Nexus 4人的应用程序,同时显示联系人号码, 而且也略低于有一个连接部分,它只显示WhatsApp的可能联系。

The "People" app on the Nexus 4 shows both contact numbers, And also a little below has a CONNECTIONS section, which shows only the WhatsApp possible contact.

有没有一种方法来查找(像人们如何应用程序做)?

Is there a way to look up(like how People app does) ?

推荐答案

如果你想知道,如果这种接触有WhatsApp的:

If you want to know if this contact has WhatsApp:

String[] projection = new String[] { RawContacts._ID };
String selection = ContactsContract.Data.CONTACT_ID + " = ? AND account_type IN (?)";
String[] selectionArgs = new String[] { "THE_CONTACT_DEVICE_ID", "com.whatsapp" };
Cursor cursor = activity.getContentResolver().query(RawContacts.CONTENT_URI, projection, selection, selectionArgs, null);
boolean hasWhatsApp = cursor.moveToNext());
if (hasWhatsApp){
    String rowContactId = cursor.getString(0)
}

和寻找到该联系人的数量已经WhatsApp的

And to find to which number of this contact has WhatsApp

projection = new String[] { ContactsContract.Data.DATA3 };
selection = ContactsContract.Data.MIMETYPE + " = ? AND " + ContactsContract.Data.RAW_CONTACT_ID + " = ? ";
selectionArgs = new String[] { "vnd.android.cursor.item/vnd.com.whatsapp.profile", rawContactId };
cursor = CallAppApplication.get().getContentResolver().query(ContactsContract.Data.CONTENT_URI, projection, selection, selectionArgs, "1 LIMIT 1");
String phoneNumber = null;
if (cursor.moveToNext()) {
    phoneNumber = cursor.getString(0);
}

这篇关于如何检查是否在android手机簿中的联系人启用了WhatsApp的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆