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;
我使用此代码获取移动联系人以及如何将所有移动联系人的应用联系人分开。
答案 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));
}