public static final String ACTION_REBOOT = "android.intent.action.REBOOT"; public static final String ACTION_REQUEST_SHUTDOWN = "android.intent.action.ACTION_REQUEST_SHUTDOWN";
//广播方式关机重启
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;
android:sharedUserId="android.uid.system"
LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional LOCAL_SRC_FILES := $(call all-java-files-under, src) LOCAL_PACKAGE_NAME := PowerActionDemo LOCAL_CERTIFICATE := platform include $(BUILD_PACKAGE)
include $(CLEAR_VARS) LOCAL_PREBUILT_EXECUTABLES := system_shutdown.sh system_reboot.sh LOCAL_MODULE_TAGS := optional include $(BUILD_MULTI_PREBUILT)
service system_shutdown /system/bin/system_shutdown.sh oneshot disabled service system_reboot /system/bin/system_reboot.sh oneshot disabled
//启动系统服务进行关机或重启
case R.id.shutdown_btn2:
Log.v(TAG, "system service->shutdown");
SystemProperties.set("ctl.start", "system_shutdwon");
break;
case R.id.reboot_btn2:
Log.v(TAG, "system service->reboot");
SystemProperties.set("ctl.start", "system_reboot");
break;
//Runtime执行linux-shell
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);
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有