简体   繁体   中英

Android: Do I need a permission?

I was looking at putting a wake lock in my app, but now I've noticed that it is deprecated to do it a certain way. I saw somewhere that I can do this:

this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, 
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

This works like wake lock, so do I still need a permission for it?

EDIT: I did more research, and WakeLock isn't deprecated, using FULL_WAKE_LOCK is... http://developer.android.com/reference/android/os/PowerManager.html (Look at FULL_WAKE_LOCK in constants)

WakeLocks并不被弃用,虽然从技术上讲,您不需要这种权限才能这样做,但保持用户屏幕的可见性并在没有允许的情况下发出警告的情况下礼貌地保持用户的礼貌是不礼貌的。

Aside from the deprecation, there is a difference between those methods for keeping the screen on. A full wake lock would keep the screen on and processor running even when the user switches to other applications. In order for it to stop you would need to release the Wake Lock. Using the WindowManager however will allow it to be handled by the OS making it much simpler for you and less likely that you will drain the end user's battery unnecessarily.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM