开发者

How to enable or disable autolock in android?

开发者 https://www.devze.com 2023-02-05 18:16 出处:网络
I have one toggle button 开发者_如何学Gowhich desides to enable and disable autolock in app,so how can we do that in app pls help me out here.

I have one toggle button 开发者_如何学Gowhich desides to enable and disable autolock in app,so how can we do that in app pls help me out here.

Thanks in advance.


Do NOT use the wakelocks. You might not release it and then you can drain the battery and annoy the user. And it requires additional permissions.

Instead do this in onCreate():

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);


If by autolock you mean stop the phone from turning the screen off due to a period of inactivity then you can do the following:

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "DoNotDimScreen");

to stop the screen from 'locking':

wl.acquire();

to allow it to lock again:

wl.release();


Im not sure about your question but, i think it refer to keep a application always on.

Check this site: PowerManager

0

精彩评论

暂无评论...
验证码 换一张
取 消