收到消息后重新启动Root Android手机

时间:2014-09-06 08:07:57

标签: android android-4.4-kitkat smsmanager

我正在开发一个应用程序,它将重新启动我的Root Android手机,当它收到来自特定号码的特定短信并且它正常工作但问题是手机重新启动后它会再次自动生成相同的消息,让手机重新启动再次

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();
            }

要重新启动我使用的root电话

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) {
        }
    }
}

任何帮助都会得到赞赏,谢谢。

0 个答案:

没有答案