0

我可以从哪些来源获得使用ContactsContract.Data.CONTENT_URI. 特别是,如果包括 SIM 卡联系人,我很感兴趣。

谢谢

4

1 回答 1

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();
}
}
于 2013-06-21T10:36:06.727 回答