Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I detect the SIM card is not inserted in Android?
    primarykey
    data
    text
    <p>I would like to check whether the SIM card is present in the phone every time the phone is booted. If there is no SIM card inserted, the application will delete all the SMS messages, removing all account credentials, deleting all phone contacts, and wiping all data on external storage automatically. But when i boot my phone, the application gets force close... The Toast that I configured is not appeared as well... Can I know how can I check the absence of SIM card? I have tried simSerial.equals("") and simSerial.equals(null), but failed... Need someone help for this... Thanks</p> <pre><code>if (simSerial.equals(null)){ Toast.makeText(testContext.getApplicationContext(), "No SIM card detected!!!", Toast.LENGTH_LONG).show(); Log.d("Message", "No SIM card"); ContentResolver cr = context.getContentResolver(); Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); while(cursor.moveToNext()){ String lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY)); Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey); cr.delete(uri, null, null); } accManager = AccountManager.get(context); Account [] acc = accManager.getAccounts(); if (acc.length &gt; 0){ for (int j=0; j&lt;acc.length; j++){ Account accountToRemove = acc[j]; accManager.removeAccount(accountToRemove, null, null); } } ContentResolver cr1 = context.getContentResolver(); Cursor cursor1 = cr1.query(Uri.parse("content://sms/"), null, null, null,null); try { while (cursor1.moveToNext()) { int id = cursor1.getInt(0); cr1.delete(Uri.parse("content://sms/" + id), null, null); } } finally { cursor.close(); } //Wipe data on SD card wipeSdCard(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    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