开发者

How to discover if the screen is ON or OFF while developing in Android?

开发者 https://www.devze.com 2023-04-08 11:27 出处:网络
How can I know if t开发者_Go百科he screen is ON/OFF?If you simply wish to poll the current state you can do so this way.

How can I know if t开发者_Go百科he screen is ON/OFF?


If you simply wish to poll the current state you can do so this way.

pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
boolean screen = pm.isScreenOn();

If you are looking to be notified when the state changes you'll have to register a Broadcast Reciver to listen for ACTION_SCREEN_OFF and ACTION_SCREEN_ON. For this particular intent you must set your Intent Filter from java code. Doing so in the Manifest does not seem to work.

0

精彩评论

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