Android:从 SIM 卡内存访问联系人

发布于 2024-09-14 16:01:08 字数 493 浏览 5 评论 0原文

我一直在尝试开发一个需要从 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 卡的联系人内存表中的列有名称吗?

I've been tryin to develop an app which requires to access contacts from SIM memory. Here is the code i've used but there is runtime exception.

{  
    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());

Any answers and solutions are appreciated. Along with that could you please tell me the exact URI to access sim card contacts?? And is there any name for colums in the sim's contacts memory table?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱情眠于流年 2024-09-21 16:01:08

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

}

Your content uri for sim contacts looks right.
I am using the following method to get contact details-

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

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文