不像重启可以使用PowerManager.reboot(),Android 对于关机没有开放的API可以使用,因此只能使用源码中的方法,比如系统没电了总会关机吧
不过APK在eclipse中编译不了,解决方法有两种
代码位置:
BatteryService.java (amdroid_march\android\frameworks\base\services\java\com\android\server)
private final void shutdownIfNoPower() {
// shut down gracefully if our battery is critically low and we are not powered.
// wait until the system has booted before attempting to display the shutdown dialog.
if (mBatteryLevel == 0 && !isPowered() && ActivityManagerNative.isSystemReady()) {
Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
}
}
不过APK在eclipse中编译不了,解决方法有两种
一种方法是放到自己的源码中编译
一种方法是eclipse加载frameworks的classes.jar,