重启android手机代码(转)

http://blog.163.com/dmg_123456/blog/static/567050632011328114654540/


package com.test.reboot;
import java.io.IOException;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class RebootAndroid extends Activity implements OnClickListener {
private Button btnReboot;
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
   setContentView(R.layout.main);
   btnReboot = (Button) findViewById(R.id.btnReboot);
   btnReboot.setOnClickListener(this);
}
@Override
public void onClick(View v) {
  // TODO Auto-generated method stub
   String cmd = "su -c reboot";
  try {
    Runtime.getRuntime().exec(cmd);
   } catch (IOException e) {
   // TODO Auto-generated catch block
   new AlertDialog.Builder(this).setTitle("Error").setMessage(
      e.getMessage()).setPositiveButton("OK", null).show();
   }
}
}

你可能感兴趣的:(重启android手机代码(转))