如何从Android设备中的移动联系人分离最新的应用程序联系人

时间:2015-11-17 10:47:36

标签: java android json android-activity packages

  ArrayList<String> contacts = new ArrayList<String>();

        Cursor c = getContentResolver().query(
                ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
                null, null, null);
        while (c.moveToNext()) {

            String contactName = c
                    .getString(c
                            .getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
            String phNumber = c
                    .getString(c
                            .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

            contacts.add(contactName + ":" + phNumber);

        }
        c.close();
        return contacts;

我使用此代码获取移动联系人以及如何将所有移动联系人的应用联系人分开。

1 个答案:

答案 0 :(得分:0)

使用此代码获取所有whatsapp联系人并将其保存为数组列表

Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
String[] projection = new String[] {
        ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
        ContactsContract.CommonDataKinds.Phone.NUMBER };
Cursor cursor = getContentResolver().query(uri, projection,
        RawContacts.ACCOUNT_TYPE + "= ?",
        new String[] { "com.whatsapp" }, null);

ArrayList<String> WContacts = new ArrayList<String>();

int indexNumber = cursor
        .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
while (cursor.moveToNext()) {

    WContacts.add(cursor.getString(indexNumber));
}