My activity runs with a partial wake lock because it is continually handling received Bluetooth data. The wake lock is set up like so:
powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakeLock");
wakeLock.acquire();
When certain events occur I want to on the display so the user can view the status. I want the display to turn on automatically, not by a user keypress. However all attempts to do this have failed. When the display turns off while running with a partial wake lock, my attempts to turn the display back and let the user see the current activity have failed. I have tried faking user activity:
PowerManager NewPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
NewPowerManager.userActivity(1, false);
Setting flags for the window:
Window win = getWindow();
win.setFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON, WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
And even releasing the wake lock and starting another that should turn on the screen:
if (wakeLock != null)
{
wakeLock.release(); // release the wakelock
}
PowerManager.WakeLock TempWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK |
PowerManager.ACQUIRE_CAUSES_WAKEUP, "TempWakeLock");
// tried | PowerManager.ON_AFTER_RELEASE to no avail
TempWakeLock.acquire();
Is there something that I am missing here? I am not trying to open up a new activity, but merely displaying my current one to the user. Has anyone else been able to do this? Thanks for any help you can give me.