Note that there are some explanatory texts on larger screens.

plurals
  1. POaccessing the sim card contacts in android
    primarykey
    data
    text
    <p>i need to access the first 10 sim card contacts on my phone. the code i used is the following:</p> <pre><code>public class simcontacts extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Uri uri16 = Uri.parse("content://icc/adn/"); String[]SimContactsName = new String[250]; String[]SimContactsNumber = new String[250]; int count = 0; ContentResolver cr = getApplicationContext().getContentResolver(); Cursor cur = cr.query(uri16, null, null, null, null); if (cur.getCount() &gt; 0) { while (cur.moveToNext()) { String id = cur.getString( cur.getColumnIndex(ContactsContract.Contacts._ID)); if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) &gt; 0) { Cursor pCur = cr.query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?", new String[]{id}, null); while (pCur.moveToNext()) { String contact = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); String number = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); SimContactsName[count]=contact; SimContactsNumber[count]=number; count++; } pCur.close(); } } } TelephonyManager telMng = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); for (int i=0; i&lt;10;i++) { Message=Message+SimContactsNumber[i]+"\n"; } Toast.makeText(this, Message, Toast.LENGTH_LONG).show(); } </code></pre> <p>when i tested it on the phone, an htc wildfire S, i got all null values. i also tested it with the phone contacts uri, ContactsContract.Contacts.CONTENT_URI, and it worked fine. how can i access SIM contacts? is there another uri i must use?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload