【问题标题】:Android: Accessing Contacts from SIM card memoryAndroid:从 SIM 卡内存中访问联系人
【发布时间】:2010-08-16 09:21:40
【问题描述】:

我一直在尝试开发一个需要从 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 的联系人记忆表中的列是否有任何名称?

【问题讨论】:

  • 你能添加你得到的异常吗?
  • 异常类似于“找不到源”,异常恰好在 c=getContentResolver().query(simUri, null, null, null, null); sim uri 正确吗,所有手机都一样吗??

标签: android mobile contacts sim-card


【解决方案1】:

您的 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();
    }

}

【讨论】:

  • "content://icc/adn" 适用于 1.6 以上的 android 版本,适用于 1.5 "content://sim/adn"。还要确保权限 -
猜你喜欢
  • 2011-10-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-25
  • 2014-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多