从Android 2.2开始,加入了一个新的锁屏API位于
android
.app.admin.DevicePolicyManager包,DevicePolicyManager类的lockNow方法可以锁住
屏幕
,查看Android源代码发现其实是从IDevicePolicyManager实现的,整个AIDL接口调用代码为:
private final IDevicePolicyManager m;
m = IDevicePolicyManager.Stub.asInterface(
Manager.get(Context.DEVICE_POLICY_));
if (m != null) {
try {
m.lockNow();
} catch (RemoteException e) {
Log.w(TAG, "Failed talking with device policy ", e);
}
}
这里 提示 大家传统的方法加入<uses-permission android:name="android.permission.DISABLE_KEYGUARD"></uses-permission>权限,使用下面代码可以锁住键盘,但屏幕不行
KeyguardManager km = (KeyguardManager)getSystem(Context.KEYGUARD_);
KeyguardLock kl= km.newKeyguardLock(KEYGUARD_);
kl.reenableKeyguard();
private final IDevicePolicyManager m;
m = IDevicePolicyManager.Stub.asInterface(
Manager.get(Context.DEVICE_POLICY_));
if (m != null) {
try {
m.lockNow();
} catch (RemoteException e) {
Log.w(TAG, "Failed talking with device policy ", e);
}
}
这里 提示 大家传统的方法加入<uses-permission android:name="android.permission.DISABLE_KEYGUARD"></uses-permission>权限,使用下面代码可以锁住键盘,但屏幕不行
KeyguardManager km = (KeyguardManager)getSystem(Context.KEYGUARD_);
KeyguardLock kl= km.newKeyguardLock(KEYGUARD_);
kl.reenableKeyguard();