实现手机重启代码

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/china_41/article/details/51244049
  private void reboot() {
        Context context = getActivity().getBaseContext();
        Toast.makeText(context, getString(R.string.system_restart), Toast.LENGTH_LONG).show();
        // mNetmodeSwitchPreference.setEnabled(false);
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(3000);
                } catch (Exception e) {
                    // TODO: handle exception
                    e.printStackTrace();
                }

                PowerManager manager = (PowerManager) getSystemService(Context.POWER_SERVICE);
                manager.reboot("restart");
            }
        }, "restart").start();
    }

展开阅读全文

没有更多推荐了,返回首页