2013-06-21 184 views

回答

2

如果你想從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(); 
} 
} 
+0

那麼,這是否意味着這從SI​​M卡聯繫人不包括在ContactsContract.Data.CONTENT_URI? – Semanticer

+1

是啊..對... – Riser

+0

錯了。 Sim contacts包含在ContactsContract.Data.CONTENT_URI中。只有當用戶選擇隱藏設備設置中的Sim聯繫人時,纔會隱藏它們。 – Santacrab