1

我一直在尝试开发一个需要从 SIM 内存访问联系人的应用程序。这是我使用的代码,但存在运行时异常。

{  
    Uri simUri = Uri.parse("content://icc/adn");
    c=getContentResolver().query(simUri, null, null, null, null);
    startManagingCursor(c);        
    getContacts();
}

private void getContacts(){
    int i=0;
    do {
        // Get the field values
        names[i++] = c.getString(0);        
    } while (c.moveToNext());

任何答案和解决方案表示赞赏。除此之外,您能否告诉我访问 sim 卡联系人的确切 URI?sim 的联系人记忆表中是否有任何列的名称?

4

1 回答 1

0

sim 联系人的内容 uri 看起来正确。我正在使用以下方法获取联系方式-

private void allSIMContact() {
    try {
        String m_simPhonename = null;
        String m_simphoneNo = null;
        String m_id = null;

        Cursor cursorSim = this.getContentResolver().query(simUri,
                null, null, null, ContactsContract.Contacts.DISPLAY_NAME);

        Log.i("PhoneContact", "total: " + cursorSim.getCount());

        while (cursorSim.moveToNext()) {
            m_id = cursorSim.getString(cursorSim.getColumnIndex("_id"));
            m_simPhonename = cursorSim.getString(cursorSim
                    .getColumnIndex("name"));
            m_simphoneNo = cursorSim.getString(cursorSim
                    .getColumnIndex("number"));

            m_simphoneNo.replaceAll("\\D", "");
            m_simphoneNo.replaceAll("&", "");
            m_simPhonename = m_simPhonename.replace("|", "");

            ListData contact= new ListData(Integer.parseInt(m_id),
                    m_simphoneNo, m_simPhonename, "", "", "", false);
            arrayList.add(contact);

        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}
于 2015-01-03T23:59:21.353 回答