【问题标题】:Retrieving the contact details of phonebook in android在android中检索电话簿的联系方式
【发布时间】:2011-09-01 11:26:36
【问题描述】:

我正在制作一个应用程序来在服务器端上传安卓设备的电话簿。 我可以得到电话簿中的姓名,但我没有得到各自姓名的联系电话。

我正在使用People.NUMBER 方法获取联系人号码。

【问题讨论】:

    标签: android numbers contacts


    【解决方案1】:
    【解决方案2】:

    使用此代码。此代码将 Contant 名称和编号存储在 Arralist 中。

    ArrayList<HashMap<String,String>> contactData=new ArrayList<HashMap<String,String>>();
    ContentResolver cr = getContentResolver();
             Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
             while (cursor.moveToNext()) {
                 try{
                 String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)); 
                 String name=cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                 String hasPhone = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)); 
                 if (Integer.parseInt(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
                     Cursor phones = getContentResolver().query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId, null, null);
                     while (phones.moveToNext()) { 
                         String phoneNumber = phones.getString(phones.getColumnIndex( ContactsContract.CommonDataKinds.Phone.NUMBER));
                         HashMap<String,String> map=new HashMap<String,String>();
                         map.put("name", name);
                         map.put("number", phoneNumber);
                         contactData.add(map);
                     } 
                     phones.close(); 
                 }
             }catch(Exception e){}
             }
    

    根据需要使用 contactData 列表。

    【讨论】:

      猜你喜欢
      • 2014-05-27
      • 1970-01-01
      • 2023-03-17
      • 1970-01-01
      • 1970-01-01
      • 2011-08-24
      • 1970-01-01
      • 2011-04-02
      • 1970-01-01
      相关资源
      最近更新 更多