1

我使用以下代码在飞行中创建一个用作拍照时预览的窗口:

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;
}

但结果并没有改变。屏幕仍然亮着!

4

0 回答 0