Last active
November 5, 2018 23:07
-
-
Save PomepuyN/cdd821eca163a3279de2 to your computer and use it in GitHub Desktop.
Allow to detect Ambient mode to switch Watch face display on Wear devices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Handler handler = new Handler(Looper.getMainLooper()); | |
final DisplayManager displayManager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE); | |
displayManager.registerDisplayListener(new DisplayManager.DisplayListener() { | |
@Override | |
public void onDisplayAdded(int displayId) { | |
} | |
@Override | |
public void onDisplayRemoved(int displayId) { | |
} | |
@Override | |
public void onDisplayChanged(int displayId) { | |
try { | |
if (displayManager.getDisplay(displayId).getState() == Display.STATE_DOZING) { | |
updateFaceDisplay(true); | |
Log.d(TAG, "onDisplayChanged: dozing"); | |
} else { | |
updateFaceDisplay(false); | |
Log.d(TAG, "onDisplayChanged: not dozing"); | |
} | |
} catch (NullPointerException exception) { | |
} | |
} | |
}, handler); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Any particular reason why you are catching/ignoring the
NullPointerException
here?