0

我一直在做很多搜索,寻找一个示例项目,向我展示如何从 android 手机中提取联系人,然后移动到单独的数据存储并将其显示在我的应用程序上。有人能帮助我吗.....

4

1 回答 1

0

获取联系人的方法

public List<String> lookupContactNames(){
    contentResolver = context.getContentResolver();
    List<String> contacts = new ArrayList<String>();
    Cursor cursor = null;
    try {
        final String[] projection = new String[] { ContactsContract.Contacts.DISPLAY_NAME };
        String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP
                + " = '1'";
        String[] selectionArgs = null;
        final String sortOrder = ContactsContract.Contacts.DISPLAY_NAME
                + " COLLATE LOCALIZED ASC";
        cursor = contentResolver.query(
                ContactsContract.Contacts.CONTENT_URI, projection,
                selection, selectionArgs, sortOrder);

        while (cursor.moveToNext()) {
            contacts
                    .add(cursor
                            .getString(cursor
                                    .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)));
        }
        return contacts;
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }

}
于 2012-04-23T05:58:18.807 回答