Android 实现关机和重启
Posted 王睿丶
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android 实现关机和重启相关的知识,希望对你有一定的参考价值。
frameworks/base/…/MdmPolicy.java
写好接口供上层调用
public void shutingdown()
RebootShutdownControl.doshutdown(mContext);
public void reboot()
android.util.Log.d(TAG,"reboot()",new Exception());
RebootShutdownControl.doreboot(mContext);
frameworks/base/…/RebootShutdownControl.java
具体实现
class RebootShutdownControl
public static void doreboot(Context context)
IPowerManager mPowerManager = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
try
mPowerManager.reboot(false, null, true);
catch (Exception e)
Log.d("RebootShutdownControl","重启失败");
public static void doshutdown(Context context)
IPowerManager mPowerManager = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
try
mPowerManager.shutdown(false, null, false);
catch (Exception e)
Log.d("RebootShutdownControl","关机失败");
以上是关于Android 实现关机和重启的主要内容,如果未能解决你的问题,请参考以下文章