开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜