Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To wake screen in android

Tags:

android

Hi i am making an Alarm Application. When Alarm Time Comes i Am showing user a Dialog. But the problem is i want to acquire the wake lock when dialog appears. just like when an sms received the screen just wakes.

i have try this one but is not working

public class Alarm extends Activity{
    PowerManager pm;
    WakeLock wl;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        pm = (PowerManager) getSystemService(POWER_SERVICE);
        wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "FlashActivity");
wl.acquire()
        showAlarmDialog();
    }
    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        wl.release();
    }
}

I have added the wakelock permission too. Help Would be appriciated :-)

like image 590
Usman Riaz Avatar asked Apr 19 '13 05:04

Usman Riaz


2 Answers

I was able to Turn the screen on this way:

wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
wl.acquire();

Hope This help. It Worked For me Though :-) Cheers

like image 82
Usman Riaz Avatar answered Oct 08 '22 02:10

Usman Riaz


You can acquire wake lock by two methods

wl.acquire(); or wl.acquire(timeout)

Try some thing like this in onResume():

PowerManager pm;
WakeLock wl;

pm = (PowerManager) getSystemService(POWER_SERVICE);
wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "FlashActivity");
wl.acquire(); Or wl.acquire(timeout)

And you are realeasing in onPause(). That is good.

like image 32
Abhi Avatar answered Oct 08 '22 04:10

Abhi