我使用以下代码在飞行中创建一个用于拍摄照片时预览的窗口:
void CreatePreviewDialog()
{
dummy_frame_layout = new DummyFrameLayout(context);
wm_params = new WindowManager.LayoutParams(
240, 320, 0, 0,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON|
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD|
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED|
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON|
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT);
wm_params.gravity = Gravity.CENTER;
wm_params.setTitle("Preview");
window_manager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
window_manager.addView(dummy_frame_layout, wm_params);
}
我的应用在后台运行,它被闹钟唤醒。如您所见,它会打开显示屏。拍摄照片后,使用以下方法销毁窗口:
void DestroyPreviewDialog()
{
((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).removeView(dummy_frame_layout);
dummy_frame_layout = null;
}
问题是屏幕仍然亮着。我想在预览窗口关闭时关闭屏幕。如何以关闭显示的方式修改DestroyPreviewDialog()
? (当然,只有在调用CreatePreviewDialog()
时发现关闭时才会关闭显示器,但这很简单。现在我需要一种方法来关闭显示器)
修改
我修改了DestroyPreviewWindow()
如下:
private void DestroyPreviewDialog()
{
wm_params.screenBrightness = 0.0f;
window_manager.updateViewLayout(dummy_frame_layout, wm_params);
((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).removeView(dummy_frame_layout);
dummy_frame_layout = null;
}
但结果不会改变。屏幕仍然亮着!