解决方案 »

  1.   

    同求   有的发一份  [email protected]   非常感谢
      

  2.   

    /**读取通讯录异步Handler*/
    private AsyncQueryHandler asyncQuery;
    /**
     * 读取通讯录
     */
    private void readContacts(){
    asyncQuery = new ContactAsyncQueryHandler(getContentResolver());
    Uri uri = Uri.parse("content://com.android.contacts/data/phones");    
            String[] projection = { "_id", "display_name", "data1", "sort_key" };    
            asyncQuery.startQuery(0, null, uri, projection, null, null,    
                    "sort_key COLLATE LOCALIZED asc");
    }

    //异步查询联系人  
        private class ContactAsyncQueryHandler extends AsyncQueryHandler {    
        
            public ContactAsyncQueryHandler(ContentResolver cr) {    
                super(cr);    
            }    
        
            protected void onQueryComplete(int token, Object cookie, Cursor cursor) {    
                if (cursor != null && cursor.getCount() > 0) {    
                 ArrayList<CallsItem> list = new ArrayList<CallsItem>();
                    cursor.moveToFirst();    
                    for (int i = 0; i < cursor.getCount(); i++) {  
                     CallsItem item = new CallsItem();    
                        cursor.moveToPosition(i);    
                        String name = cursor.getString(1);    
                        String number = cursor.getString(2);    
                        String sortKey = cursor.getString(3);  
                        if (number.startsWith("+86")) {    
                            number = number.substring(3); //去掉+86   
                        }
                        item.name = name;
                        item.number = number;
                        item.sort = sortKey;
                        list.add(item);
    //                    System.out.println("name:" + name + " number:" + number + " sort:" + sortKey);
                    }
                    app.allList = list;
                }    
            }    
        }