1

I have an alarm which periodically (every 30 sec) wakes up my device. When the alarms starts, I use the following code to open a window:

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

Then, I close the window with the following code:

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

The problem is as follows. Suppose that the device is in standby mode. When the alarm happens it calls CreatePreviewDialog that turns on the display. When the DestroyPreviewDialog is called, I would like that the device returns in its standby mode or, at least, that the display turns off but I have not found any solution to this problem. I've also added the following code before closing the window in DestroyPreviewDialog:

    wm_params.screenBrightness = 0.0f;
    window_manager.updateViewLayout(dummy_frame_layout, wm_params);

but nothing happens. The screen remains on showing the lockscreen till the next alarm happens. Just like if the application is in foreground. Any idea?

user2923045
  • 369
  • 2
  • 6
  • 16

1 Answers1

0

There is no way to do that... Look at this question: Force standby

You need a permission that is for system applications...

Community
  • 1
  • 1
phemt.latd
  • 1,775
  • 21
  • 33