我想以某种方式覆盖锁定屏幕按钮。我的想法是,我想保持屏幕清醒一段时间,我这样做了
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
"MyWakelockTag");
wakeLock.acquire();
}
无论如何,我的手机上有一个翻盖,当我打开翻盖时,我的手机被锁定了。当我打开翻盖时,我怎么能停止锁定屏幕事件?这就是为什么我需要知道是否可以暂时停止锁屏功能。
答案 0 :(得分:1)
对于Flipcover,你必须检查SensorManager和电源/锁定按钮,你可以尝试这个 -
public class ScreenReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
switch (action) {
case Intent.ACTION_SCREEN_OFF:
BaseActivity.unlockScreen();
break;
case Intent.ACTION_SCREEN_ON:
// and do whatever you need to do here
BaseActivity.clearScreen();
}
}
}
但我不确定它是否会起作用