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.
精彩评论