2012-04-23 79 views
0

我一直在做大量的搜索工作,寻找一些示范项目,向我展示如何从android手机中提取联系人,并移至单独的数据存储并将其显示在我的应用中。可有一个人帮我,请.....Android联系人问题

+1

从DB你只需要姓名联系? – 2012-04-23 02:20:08

+0

可能的重复:http://stackoverflow.com/questions/9650750/how-to-get-mobile-number-form-contact&http://stackoverflow.com/questions/3476957/where-to-store-a-联系列表上-AN-的Android手机 – 2012-04-23 08:48:58

回答

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(); 
     } 
    } 

}