android系统烦人重新启动参考博客:
http://blog.sina.com.cn/s/blog_69b5d2a50101fvqp.html
http://blog.csdn.net/cuiran/article/details/19164817
一.android系统重启
1.用runtime来实现,即:
try
{
Runtime.getRuntime().exec("su");
Runtime.getRuntime().exec("reboot");
}
catch (IOException e)
{ }
但是在自己身边的几个平板和手机设备都没有实现reboot,原因不明,看到也有很多人通过这个方法实现了设备的reboot。
2.用广播的形式:
public void reboot(Context context){
LogsUtil.i(TAG, " reboot");
Intent i = new Intent(Intent.ACTION_REBOOT);
i.putExtra("nowait", 1);
i.putExtra("interval", 1);
i.putExtra("window", 0);
context.sendBroadcast(i);
LogsUtil.i(TAG, " reboot over");
}
这个方法需要应用签名,很麻烦,换个设备就需要重新签名,我没有尝试。
3.参考“Android ICS关机跟重新启动功能研究”一文
Intent iReboot = new Intent(Intent.ACTION_REBOOT);
iReboot.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(iReboot);
这个方法一开始在4.2的平板上可以实现,以为没有问题了,结果在4.0的手机上报异常No activity founded to handle this intent。这个应该是android版本的问题了,没办法。
Powermanger
PowerManager pm = (PowerManager)getApplicationContext().getSystemService(Context.POWER_SERVICE);
pm.reboot(null);
尝试这个方法,在4.2和4.0的系统上都OK。
以上需要系统root权限,adb push xxx.apk system/app安装,一定要在这个目录下才能成为系统应用,来获取更大的操作权限
顺便说一下,系统关机的代码
Intent shutdown = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
shutdown.putExtra(Intent.EXTRA_KEY_CONFIRM, showShutdownDialog);
shutdown.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(shutdown);
二.应用程序重启
//查找启动页,一般是SplashActivity
Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); //销毁所有的Activity,必须的哦
startActivity(i);