I have made an app that wakes up the screen when it receives a text message. I came up with the following code to wake the screen.
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
boolean isScreenOn = pm.isScreenOn();
if(!isScreenOn ){
final PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My tag");
wl.acquire();
Toast.makeText(getBaseContext(), "This is WAKEUP SCREEN", Toast.LENGTH_SHORT).show();
Thread timer = new Thread(){
public void run(){
try {
sleep(5000);
} catch (InterruptedException e) {
// TODO: handle exception
}finally{
wl.release();
}
}
};
timer.start();
}
Now the problem is that if I comment out or remove the statement Toast.makeText(getBaseContext(), "This is WAKEUP SCREEN", Toast.LENGTH_SHORT).show(); my screen wont wakeup. I am not sure what is the problem here… and I am using android 2.3.
Use
PowerManager.SCREEN_DIM_WAKE_LOCK|PowerManager.ACQUIRE_CAUSES_WAKEUPinstead of justPowerManager.SCREEN_DIM_WAKE_LOCK, and see if that helps.