Android 11.0 接口方式实现 休眠和唤醒
Posted 王睿丶
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android 11.0 接口方式实现 休眠和唤醒相关的知识,希望对你有一定的参考价值。
△需要权限
- 系统权限:
android:sharedUserId="android.uid.system"
- 其他权限:
<uses-permission android:name="android.permission.WAKE_LOCK"/>
- 其他权限:
<uses-permission android:name="android.permission.DEVICE_POWER"/>
frameworks/base/…/MdmPolicy.java
写好接口供上层调用
public void sleep()
SleepAndWakeLockControl.sleep(mContext);
public void wake()
SleepAndWakeLockControl.wake(mContext);
frameworks/base/…/SleepAndWakeLockControl.java
具体实现
class SleepAndWakeLockControl
public static void sleep(Context context)
IPowerManager mPowerManager = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
try
mPowerManager.goToSleep(SystemClock.uptimeMillis()+1,0,0);
catch (Exception e)
Log.d("SleepAndWakeLockControl","休眠失败");
public static void wake(Context context)
IPowerManager mPowerManager = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
try
mPowerManager.wakeUp(SystemClock.uptimeMillis()+1,0,"wakeUp",context.getOpPackageName());
catch (Exception e)
Log.d("SleepAndWakeLockControl","唤醒失败");
以上是关于Android 11.0 接口方式实现 休眠和唤醒的主要内容,如果未能解决你的问题,请参考以下文章