7

I've just been reading in the UserGuide on variables:

Night Mode
%NIGHT
The current Android Night Mode.
One of on, off or auto.
If auto, Android will decide whether it should be in Night Mode itself.

Which raised the question: What is "Android Night Mode"? Obviously it is something Android itself implements and decides on whether it is active or not (mode: auto), and that decision can be overruled (mode: on/off). But what exactly does that mean to the user? What triggers it (time? light conditions?), and what are the consequences (mute? dim?)?

I've done a Google search on the terms – but all that came up with were either apps to toggle "night mode", or apps having a "night theme".

I've checked our site for questions on "night mode", but found no complete answer to my question there. Some indicators, though:

Is there any complete answer to my question?

4

"Night Mode" is actually pretty intuitive as far as the name goes.

The OS basically attempts to estimate both sunrise and sunset, based on the current date and your latitude relative to the equator. It then determines that it is "night" if the current time falls either before sunrise or after sunset.

You can find the code for this in the base frameworks, specifically in the TwilightCalculator. There is an associated service that attempts to refresh this sunrise/sunset data in the background if you move around, called TwilightService.

In the latter file, you can also see what Android does in the event that it does not have an accurate location (I would assume this occurs if you turn off location access and such):

// In the case there is no location available (e.g. GPS fix or network location
// is not available yet), the longitude of the location is estimated using the timezone,
// latitude and accuracy are set to get a good average.

It later sets the latitude value to 0 for the calculation, which would be the equator.

It also tries to schedule updates so that they only run at day/night boundaries if you're not moving around much. For example, if it's the middle of the day and it's already calculated sunset, it won't run again until after sunset has passed (and if it's nighttime, it will run after tomorrow's calculated sunrise).

The affects of entering "Night Mode" are entirely app dependent. There is an API that lets apps query this information if they so choose, as well as APIs to instruct the system as to which UI modes they will support. It has no real immediate impact on the system itself, though.

| improve this answer | |
  • Thanks, eldarerathis! That was about what I already expected, but didn't find any proof for so far. As I never noticed any related "behavior": do you know of anything to "test" this? Is there e.g. a specific part of Android itself where it should be reflected, or did you notice any apps making use of this? What are possible/expected reactions (what should it be good for)? I mean, first thing coming to mind is display related stuff, but I'd guess that rather uses the ambient light sensor or the like to "kick in" (makes more sense to me at least). – Izzy Jan 26 '15 at 22:30
  • I can't list definitively any apps that use this, aside from Tasker's ability to expose this to you (as you already have seen). One simple test would be to create a task that's based on the %NIGHT variable and try it in a dark room during the middle of the day. Throwing together an app to test it wouldn't be too hard, as well, because it's just a resource specifier (search this page for "notnight"). – eldarerathis Jan 26 '15 at 22:42
  • 1
    Also, Google Maps does appear to use this, at least outwardly. Whether or not it uses some other data/calculations on top of night mode is not entirely clear, but if you're using the navigation at nighttime it uses a dark theme (black background and such instead of white). – eldarerathis Jan 26 '15 at 22:44
  • And that theming stuff is what I've wondered about. To me, it makes no sense binding that to "time", but rather to light conditions. So I was wondering what that night-mode stuff could be useful for. Currently it rather looks to me like "some fancy thing without real use" – so why would that be built into Android's core? For the Google Maps example I already mentioned the "tunnel"; passing such is not depending on daytime or night, so I take that rather as a theming thing using the same term, but not the same "feature". – Izzy Jan 26 '15 at 23:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.