使用相机时屏幕关闭(Android)

时间:2012-05-08 11:01:29

标签: android

有什么方法可以让我在预览相机时保持屏幕清醒(不要让它关闭)?

谢谢!

2 个答案:

答案 0 :(得分:1)

最简单的方法是使用WakeLock

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = pm.newWakeLock(
        pm.SCREEN_DIM_WAKE_LOCK, "My wakelook");
// This will make the screen and power stay on
// This will release the wakelook after 1000 ms
wakeLock.acquire(1000);

// Alternative you can request and / or  release the wakelook via:
// wakeLock.acquire(); wakeLock.release();

答案 1 :(得分:1)

  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | 
    WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
                     WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

使用它对我有用!