turn wifi on/off when phone screen lock(sleep)
Heloo all im new to 开发者_运维知识库android and im trying to create an application that turn the wifi off when the screen lock and enable the wifi every spacific time to fetch data and turn it off again while the phone in lock screen
i know how to 1)set the Timer 2)how to enable Wifi 3)disable Wifi
but i need to know how to listen to the lock screen event so when the screen locked my code will start.
any help plzz?
To detect screen wake, set a BroadcastRecever ACTION_SCREEN_ON. To detect screen unlock, use ACTION_USER_PRESENT.
- Use AlarmManager if you need your code to be run at scheduled intervals.
- Use WifiManager. Permissions are needed.
精彩评论