Android:如何使用SDK访问SIM联系人表?

发布于 2024-09-08 17:11:13 字数 1837 浏览 10 评论 0原文

我正在尝试使用此查询来读取 SIM 卡上的联系人。

            cur = managedQuery(Uri.parse("content://icc/adn")
                ,null
                ,null
                ,null
                ,null
                );

应用程序具有 READ_CONTACTS 和 WRITE_CONTACTS 权限。然而,查询返回异常。

java.lang.NullPointerException
    at android.os.Parcel.readException(Parcel.java:1224)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:160)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114)
    at android.content.ContentProviderProxy.bulkQuery(ContentProviderNative.java:369)
    at android.content.ContentProviderProxy.query(ContentProviderNative.java:388)
    at android.content.ContentResolver.query(ContentResolver.java:202)
    at android.app.Activity.managedQuery(Activity.java:1502)
    at com.example.delirious.delirio.onCreate(delirio.java:38)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2544)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2621)
    at android.app.ActivityThread.access$2200(ActivityThread.java:126)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:4595)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:521)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
    at dalvik.system.NativeStart.main(Native Method)

怎么了?

I am trying to use this query to read the contacts on the SIM.

            cur = managedQuery(Uri.parse("content://icc/adn")
                ,null
                ,null
                ,null
                ,null
                );

The application has READ_CONTACTS and WRITE_CONTACTS permissions. Yet, the query returns an exception.

java.lang.NullPointerException
    at android.os.Parcel.readException(Parcel.java:1224)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:160)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114)
    at android.content.ContentProviderProxy.bulkQuery(ContentProviderNative.java:369)
    at android.content.ContentProviderProxy.query(ContentProviderNative.java:388)
    at android.content.ContentResolver.query(ContentResolver.java:202)
    at android.app.Activity.managedQuery(Activity.java:1502)
    at com.example.delirious.delirio.onCreate(delirio.java:38)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2544)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2621)
    at android.app.ActivityThread.access$2200(ActivityThread.java:126)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:4595)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:521)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
    at dalvik.system.NativeStart.main(Native Method)

What's wrong?

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

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

发布评论

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

评论(3

死开点丶别碍眼 2024-09-15 17:11:13

我使用以下代码来获取 simcard 详细信息..它工作正常

Uri simUri = Uri.parse("content://icc/adn");
        Cursor cursorSim    = this.getContentResolver().query(simUri, null, null,null, null);

         while (cursorSim.moveToNext()) {           
             listName.          add(cursorSim.getString(cursorSim.getColumnIndex("name")));
             listContactId.     add(cursorSim.getString(cursorSim.getColumnIndex("_id")));      
             listMobileNo.      add(cursorSim.getString(cursorSim.getColumnIndex("number")));
            }

这里的名称、_id、数字是 simcard 表中的列名称

i have used the following code to get the simcard details..It works fine

Uri simUri = Uri.parse("content://icc/adn");
        Cursor cursorSim    = this.getContentResolver().query(simUri, null, null,null, null);

         while (cursorSim.moveToNext()) {           
             listName.          add(cursorSim.getString(cursorSim.getColumnIndex("name")));
             listContactId.     add(cursorSim.getString(cursorSim.getColumnIndex("_id")));      
             listMobileNo.      add(cursorSim.getString(cursorSim.getColumnIndex("number")));
            }

Here the name, _id, number are column names from the simcard table

痴者 2024-09-15 17:11:13

我明白了,

String simUrl = "content://icc/adn";
Intent intent = new Intent();
            Log.d(TAG, "simUrl=" + simUrl);
            intent.setData(Uri.parse(simUrl));
            Uri uri = intent.getData();
            Cursor mCursor = context.getContentResolver().query(uri, null,
                    null, null, null);

然后,for(...){...},你知道

i got it,

String simUrl = "content://icc/adn";
Intent intent = new Intent();
            Log.d(TAG, "simUrl=" + simUrl);
            intent.setData(Uri.parse(simUrl));
            Uri uri = intent.getData();
            Cursor mCursor = context.getContentResolver().query(uri, null,
                    null, null, null);

and then, for(...){...}, you know

两相知 2024-09-15 17:11:13

我刚刚实现了一小段代码,用于显示 SIM 卡中的联系人列表。希望它可以帮助你

private void displaySIMContacts() {
    try {
        String simPhoneId = null;
        String simPhoneNum = null;
        String simPhoneName = null;

        Uri simUri = Uri.parse("content://icc/adn");
        Cursor simCursor = getContentResolver().query(simUri, null, null, null, null);

        while(simCursor.moveToNext()) {
            simPhoneId = simCursor.getString(simCursor.getColumnIndex("_id"));
            simPhoneNum = simCursor.getString(simCursor.getColumnIndex("name"));
            simPhoneName = simCursor.getString(simCursor.getColumnIndex("number"));
            Log.v("!!!", " id = " + simPhoneId + " - name = " + simPhoneName
                + " - number = " +simPhoneNum);
        }
    }
    catch (Exception e) {
       e.printStackTrace();
    }
}

I just implemented a small piece of code that used to display a list of contacts in SIM card. Hope that it can help you

private void displaySIMContacts() {
    try {
        String simPhoneId = null;
        String simPhoneNum = null;
        String simPhoneName = null;

        Uri simUri = Uri.parse("content://icc/adn");
        Cursor simCursor = getContentResolver().query(simUri, null, null, null, null);

        while(simCursor.moveToNext()) {
            simPhoneId = simCursor.getString(simCursor.getColumnIndex("_id"));
            simPhoneNum = simCursor.getString(simCursor.getColumnIndex("name"));
            simPhoneName = simCursor.getString(simCursor.getColumnIndex("number"));
            Log.v("!!!", " id = " + simPhoneId + " - name = " + simPhoneName
                + " - number = " +simPhoneNum);
        }
    }
    catch (Exception e) {
       e.printStackTrace();
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文