0

I'm implementing my own alarm clock and want to take care about situations when it's time to alarm and display of my emulator is switched off.

I'm trying to handle it with the following code in onCreate() of my activity that pops up when it's time to alarm:

PowerManager pm = (PowerManager)mContext.getSystemService(
                                          Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(
                                      PowerManager.SCREEN_DIM_WAKE_LOCK
                                      | PowerManager.ON_AFTER_RELEASE,
                                      TAG);
wl.acquire();
wl.release();

then I turn display off with a "switch-button" of my emulator. The music is playing but my display isn't waked up.

Also I tried to do it in this way:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

but the result was the same.

How can I handle this problem?

Dmitry
  • 85
  • 10

1 Answers1

1

Use the ACQUIRE_CAUSES_WAKEUP flag to turn-ON the screen.

TheCodeArtist
  • 21,479
  • 4
  • 69
  • 130
  • I have tried this in onCreate() of my activity but my application crashes with IllegalArgumentException "Unnable to start activity" – Dmitry Sep 27 '12 at 21:33
  • I just changed to FULL_WAKE_LOCK flag and everything became OK :) Thanks a lot ! – Dmitry Sep 27 '12 at 21:49