我想在每次手机启动时检查手机中是否存在SIM卡。如果没有插入SIM卡,应用程序将删除所有SMS消息,删除所有帐户凭据,删除所有电话联系人,并自动擦除外部存储上的所有数据。但是当我启动手机时,应用程序被强行关闭......我配置的Toast也没有出现......我能知道怎样才能检查SIM卡的缺失情况?我已经尝试过simSerial.equals(“”)和simSerial.equals(null),但是失败了...需要有人帮忙...谢谢
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 > 0){
for (int j=0; j<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();
}