Android: how to access SIM contact table using SDK?

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

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

The app has the permissions READ_CONTACTS and WRITE_CONTACTS. However, the request 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?

+6
java android sim-card
source share
3 answers

I used the following code to get information about the sim card. It works great

 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 the column names from the simcard table

+8
source share

I recieved 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

+2
source share

I just implemented a small piece of code that was used to display the contact list on a SIM card. Hope this helps you.

 private void displaySIMContacts() { try { String simPhoneId = null; String simPhoneNum = null; String simPhoneName = null; Uri simUri = Uri.parse("content://icc/adn"); Cursor simCusor = 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.getColumIndex("number); Log.v(TAG, " id = " + simPhoneId + " - name = " + simPhoneName + " - number = " + simPhoneNumber); } } catch (Exception e) { e.printStackTrace(); } } 
+2
source share

All Articles