0

Scenario:

I have an activity that is running in foreground.. After a while, screen will auto lock.

Later, I receive a new Intent that requires the screen to be shown again regardless of lock screen..

How should I turn on the screen while this activity is just behind the lock screen (when you press lock button again, you will see the activity)

I only know how to turn on the screen when starting an activity

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // make incoming call show on locked screen
    getWindow().addFlags(
            WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
                    WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
}

Now I want to turn on the screen after activity has already been created but been in the background after onStop()..

I tried the following but it does not work:

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    handleCallingIntent(intent);

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    final PowerManager.WakeLock wl = pm.newWakeLock(
            PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "Incoming Call");
    wl.acquire();
    mDismissButton.postDelayed(new Runnable() {
        @Override
        public void run() {
            // just to test if screen will be on for 10s
            wl.release();
        }
    }, 10000L);
}
xialin
  • 7,686
  • 9
  • 35
  • 66

1 Answers1

0

You should change screen brightness whenever activity is in foreground.

WindowManager.LayoutParams params = getWindow().getAttributes();
params.screenBrightness = 0;
getWindow().setAttributes(params);

Moreover, you can set brightness value to -1/1 for further brightness features.

atifali
  • 193
  • 16
  • I don't get you.. you are trying to dim the screen, aren't you? by setting brightness to zero... I want to show the screen from lock screen – xialin Sep 15 '15 at 15:27