Android: how to access the SIM contact table using the SDK?

試著忘記壹切 提交于 2019-11-29 07:14:27
Durai

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

David Pai

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

Nguyen

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();
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!