我正面临着这里提到的问题Screen Blackout。我无法找到它的解决方案,请告诉我是否有办法解决它。
答案 0 :(得分:0)
今天我也遇到了这个问题,我发现了一个kida hacky解决方案。
关键是重新启用键盘锁,关闭它并再次重新启用它。
private KeyguardManager.KeyguardLock mLock;
public static final String KEYLOCK_NAME = "key_lock";
@Override
protected void onPause() {
super.onPause();
// Call it anywhere you need, onPause is just an example
if (enableKeyguard()) {
disableKeyguard();
enableKeyguard();
}
}
/**
* Dismisses lockscreen
*/
public void disableKeyguard() {
if (mLock == null) {
KeyguardManager manager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
mLock = manager.newKeyguardLock(KEYLOCK_NAME);
mLock.disableKeyguard();
}
}
/**
* Re-enables lockscreen
* @return true if lockscreen was previously disabled and now it is enabled again, otherwise false
*/
public boolean enableKeyguard() {
if (mLock != null) {
mLock.reenableKeyguard();
mLock = null;
return true;
}
return false;
}
答案 1 :(得分:0)
您可以使用此代码:
private BroadcastReceiver mScreenOffReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
SimpleLog.i(TAG, intent.getAction());
if(intent.getAction().equals(Intent.ACTION_SCREEN_OFF)
|| intent.getAction().equals(Intent.ACTION_SCREEN_ON)){
keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
keyguardLock = keyguardManager.newKeyguardLock("");
keyguardLock.disableKeyguard();
startActivity(lockIntent);
// **This line is important!!!**
keyguardLock.reenableKeyguard();
}
}
};