重启应用

private void restartApp() {          final Intent intent = getPackageManager().getLaunchIntentForPackage(getPackageName());          intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);          startActivity(intent);  } 

RunTime重启手机

 case R.id.shutdown_btn3:                try{                    Log.v(TAG, "root Runtime->shutdown");                    //Process proc =Runtime.getRuntime().exec(new String[]{"su","-c","shutdown"});                    Process proc =Runtime.getRuntime().exec(new String[]{"su","-c","reboot -p"});                    proc.waitFor();                }catch(Exception e){                    e.printStackTrace();                }                break;            case R.id.reboot_btn3:                try {                     Log.v(TAG, "root Runtime->reboot");                    Process proc =Runtime.getRuntime().exec(new String[]{"su","-c","reboot "});                    proc.waitFor();                }catch (Exception ex){                    ex.printStackTrace();                }                break;

反射调用重启手机

try {     //获得ServiceManager类     Class ServiceManager = Class.forName("android.os.ServiceManager");     //获得ServiceManager的getService方法     Method getService = ServiceManager.getMethod("getService", java.lang.String.class);     //调用getService获取RemoteService     Object oRemoteService = getService.invoke(null,Context.POWER_SERVICE);     //获得IPowerManager.Stub类     Class cStub = Class.forName("android.os.IPowerManager$Stub");     //获得asInterface方法     Method asInterface = cStub.getMethod("asInterface", android.os.IBinder.class);     //调用asInterface方法获取IPowerManager对象     Object oIPowerManager = asInterface.invoke(null, oRemoteService);     //获得shutdown()方法     Method shutdown = oIPowerManager.getClass().getMethod("shutdown",boolean.class,boolean.class);                        //调用shutdown()方法                        shutdown.invoke(oIPowerManager,false,true);                } catch (Exception e) {                  Log.e(TAG, e.toString(), e);             }

广播重启手机

            //广播方式关机重启            case R.id.shutdown_btn1:                Log.v(TAG, "broadcast->shutdown");                Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);                intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false);                //其中false换成true,会弹出是否关机的确认窗口                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);                startActivity(intent);                break;            case R.id.reboot_btn1:                Log.v(TAG, "broadcast->reboot");                Intent intent2 = new Intent(Intent.ACTION_REBOOT);                intent2.putExtra("nowait", 1);                intent2.putExtra("interval", 1);                intent2.putExtra("window", 0);                sendBroadcast(intent2);                  break;

更多相关文章

  1. Android实现模拟点击的一种方法
  2. Android scrollview嵌套listview 滑动事件冲突的解决方法
  3. Android Studio sync 失败解决方法
  4. android监听手机网络连接状态改变的后台服务
  5. Android全屏的两种方法
  6. java/android查询手机固话归属地、GSM卡信息

随机推荐

  1. Android(安卓)StatFs类
  2. (2.2.8.1)关于Android(安卓)Studio里的Grad
  3. Kotlin + Android(安卓)KTX让开发更简单
  4. Android(安卓)Monkey的使用
  5. Android: Type Method 'NewStringUTF' co
  6. MediaBrowserService 音乐播放项目《IT蓝
  7. TextView获取父控件的绘图状态
  8. Android(安卓)中的显示单位
  9. Android各版本间API的差异 - (Share)Acti
  10. 使用SQLiteOpenHelper 和使用ContentProv