I am working on a Application that will restart my Rooted Android phone, when it receives a particular SMS from Particular Number and its working fine for me but issue is that after phone restarts it Auto generate same message again that make phone restart again and again
if (intent.getAction()
.equals("android.provider.Telephony.SMS_RECEIVED")) {
Bundle bundle = intent.getExtras(); // ---get the SMS message passed
// in---
SmsMessage[] msgs = null;
String msg_from = "";
String msg_body = "";
if (bundle != null) {
try {
Object[] pdus = (Object[]) bundle.get("pdus");
SmsMessage sms = SmsMessage.createFromPdu((byte[]) pdus[0]);
Log.i("cs.fsu",
"smsActivity : SMS is <" + sms.getMessageBody()
+ ">");
// strip flag
msg_body = sms.getMessageBody();
msg_from = sms.getOriginatingAddress();
while (msg_body.contains("FLAG"))
msg_body = msg_body.replace("FLAG", "");
} catch (Exception e) {
Log.d("Exception caught", e.getMessage());
}
} else {
Log.i("cs.fsu", "smsActivity : NULL SMS bundle");
}
if (msg_from.equals("+91XXXXXXX")
&& msg_body.equals("Restart Phone")) {
Log.e("Message Data in condition", "Message Body:-" + msg_body
+ "Message No." + msg_from);
Toast.makeText(context, msg_body, 550).show();
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
rebootSU();
}
And to reboot my rooted phone i used
public static void rebootSU() {
Runtime runtime = Runtime.getRuntime();
Process proc = null;
OutputStreamWriter osw = null;
StringBuilder sbstdOut = new StringBuilder();
StringBuilder sbstdErr = new StringBuilder();
String command = "/system/bin/reboot";
try { // Run Script
proc = runtime.exec("su");
osw = new OutputStreamWriter(proc.getOutputStream());
osw.write(command);
osw.flush();
osw.close();
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (osw != null) {
try {
osw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
try {
if (proc != null)
proc.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
if (proc.exitValue() != 0) {
}
}
}
Any help will b Appreciated ,Thanks.