2015-04-23 106 views
0

在我的Android应用程序中,我想检索所有SIM卡和手机联系人。如果我单独执行代码,它可以正常工作,但如果我将它结合起来,我只需获得手机通讯录。如何获得两个联系? 我对SIM卡通讯录代码:以编程方式在Android中检索SIM卡联系人

private void SIMContacts() 
 
{ 
 
    try 
 
    { 
 
     String strPhonename = null; 
 
     String strphoneNo = null; 
 

 
    Uri simUri = Uri.parse("content://icc/adn"); 
 
    Cursor cursorSim = this.getContentResolver().query(simUri,null,null,null,null); 
 

 
    while (cursorSim.moveToNext()) 
 
    {  
 
     strPhonename =cursorSim.getString(cursorSim.getColumnIndex("name")); 
 
     strphoneNo = cursorSim.getString(cursorSim.getColumnIndex("number")); 
 
     strphoneNo.replaceAll("\\D",""); 
 
     strphoneNo.replaceAll("&", ""); 
 
     strPhonename=strPhonename.replace("|",""); 
 

 
     Log.i("Contact: ", "name: "+strPhonename+" phone: "+strphoneNo); 
 
    }   
 
} 
 
catch(Exception e) 
 
{ 
 
    e.printStackTrace(); 
 
} 
 
}

回答

1

尝试从AA ArrayList中使用,并得到号码列表

public void getNumber(ContentResolver cr) { 

    public static ArrayList<String> aa = new ArrayList<String>(); 
    Cursor phones = cr.query(
      ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, 
      null, null); 

    // System.out.println("Phone" + phones.getCount()); 

    while (phones.moveToNext()) { 
     String name = phones 
       .getString(phones 
         .getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)); 
     phoneNumber = phones 
       .getString(phones 
         .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); 
     // System.out.println(".................." + phoneNumber); 
     aa.add(name); 
     aa.add(phoneNumber); 
    } 
    phones.close();// close cursor 



    // display contact numbers in the list 
} 
+0

这给这只手机的联系人列表。我是能够检索但我希望将手机通讯录和SIM卡通讯录放在一起。 –

相关问题