开发者

turn wifi on/off when phone screen lock(sleep)

开发者 https://www.devze.com 2023-04-04 00:17 出处:网络
Heloo all im new to 开发者_运维知识库android and im trying to create an application that turn the wifi off when the screen lock

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.

  1. Use AlarmManager if you need your code to be run at scheduled intervals.
  2. Use WifiManager. Permissions are needed.
0

精彩评论

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

关注公众号