Reputation: 2321
i need to prevent mt app from sleeping.
so , at first i add this permission :
< uses-permission android:name="android.permission.WAKE_LOCK"/>
the below codes in Activity :
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl= pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"sleeplock");
too , in app installing show permission:
But after all above Efforts, the Device fall to asleep(Off)
yet!
where is problem?
Upvotes: 0
Views: 103
Reputation: 1006724
First, you need to acquire()
the WakeLock
to have it take effect.
Second, if your application has a UI, and you only want to keep the screen on while your UI is in the foreground, remove all of your WakeLock
logic and just call setKeepScreenOn(true)
on any widget in your UI.
Upvotes: 1
Reputation: 137398
Read The Friendly Manual: http://developer.android.com/reference/android/os/PowerManager.WakeLock.html
You need to call:
wl.acquire()
And then
wl.release()
Upvotes: 2