1

I use the following code to create on the flight a window used as preview when a picture is taken:

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

My app runs in background and it is waked-up by an alarm. It turns-on the display as you can see. As soon as the picture is taken, the window is destroyed using the following method:

void DestroyPreviewDialog()
{
    ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).removeView(dummy_frame_layout);
    dummy_frame_layout = null;
}

The problem is that the screen remains on. I would like to turn-off the screen when the preview window is closed. How does DestroyPreviewDialog() should be modified in such a way to turn-off the display? (of course the display should be turned off only if it was found turned off when CreatePreviewDialog() was called, but this is simple. For now I need a way to turn off the display)

EDIT I've modified DestroyPreviewWindow() as follows:

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

but the results does not change. Screen remains on and bright!

Alex K
  • 8,269
  • 9
  • 39
  • 57
user2923045
  • 369
  • 2
  • 6
  • 16
  • Duplicate of: http://stackoverflow.com/questions/4545079/lock-the-android-device-programatically – hatcyl Jan 18 '14 at 08:41
  • @hatcyl could you please explain me why it is a duplicate??? – user2923045 Jan 18 '14 at 08:55
  • If you follow that link, it will tell you how to lock the phone programmaticly. – hatcyl Jan 18 '14 at 09:09
  • @hatcyl, I do not want to lock the phone. My message does not state that I want to lock the phone... I want to turn off the display. – user2923045 Jan 18 '14 at 14:08
  • Let me clarify, the link I provided "locks the phone", but part of that is turning off the screen. It's the same method all the "turn off your screen with an icon" apps use. – hatcyl Jan 18 '14 at 20:01

0 Answers0