What is the use of android permission Wake Lock? [

2019-03-23 14:59发布

When and why to use the android permission <uses-permission android:name="android.permission.WAKE_LOCK" />. Please provide sample code regarding wake lock.

5条回答
贪生不怕死
2楼-- · 2019-03-23 15:38

To wake device when its sleep i.e when user is not present in lay term screen lock

查看更多
神经病院院长
3楼-- · 2019-03-23 15:38

A wake lock is a mechanism to indicate that your application needs to have the device stay on.

Any application using a WakeLock must request the android.permission.WAKE_LOCK permission in an <uses-permission> element of the application's manifest. Obtain a wake lock by calling newWakeLock(int, String).

查看更多
时光不老,我们不散
4楼-- · 2019-03-23 15:40

In the manifest:

<uses-permission android:name="android.permission.WAKE_LOCK" />
查看更多
Root(大扎)
5楼-- · 2019-03-23 15:41

You can use a wakelock for keeping the screen turned on - you can see an example in this code.

If you want more information, you have to specify your question.

查看更多
孤傲高冷的网名
6楼-- · 2019-03-23 15:45

WakeLock is a mechanism to keep the device on, as written here and here

It is used for example when you need to do things even when the device seems to be asleep, like downloading files from the internet.

Wakelocks should never be used unless you really need them. The reason is that they consume more battery, and if you have a bug that won't release them when needed, your app will keep consuming the battery of the device. There are even apps to detect such problematic apps (like "wakelock detector") .

Also, a small tip for people who just wish to let the screen stay on (as long as the app is shown): you don't need (and you shouldn't need) the wakeLock permission. Instead, you should just set "android:keepScreenOn="true"" on the layout of the current activity. More about this is talked about on the lecture "Coding for Life -- Battery Life, That Is" (presentation here)

查看更多
登录 后发表回答