我想在每次手机启动时检查手机中是否存在 SIM 卡。如果没有插入 SIM 卡,应用程序将删除所有短信、删除所有帐户凭据、删除所有手机联系人并自动擦除外部存储上的所有数据。但是当我启动手机时,应用程序会强制关闭......我配置的 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();
}