androidgoogle-glassgoogle-mirror-apigdk

Wake Google Glass' Screen to Display Current Information Based on Location


I am building an immersion app for driving that should not display anything on screen and run in the background until the driver reaches some specific location marker. Once at or near this location, based on GPS position, the screen should wake up, and display something relevant to that location. This seems straightforward, but I have not found any solutions to do so that make sense to me. Getting and comparing GPS info is not a problem, but how do you wake up the screen based on some event, or a change of something, or something you have programmatically defined?

Would this be something I should handle with Mirror API instead to push notifications to the timeline?

The reason I am using an immersion is due to the fact that I do not want the driver to be able to multitask, as would a live card allow. Instead, he/she should start the app, and it will take over the rest (pushing notifications to the display). These notifications are free to disappear after several seconds or whenever Glass feels like going back to "sleep."

Any ideas on this matter would be greatly appreciated. I have read stuff about wake lock, but am not sure if that pertains to what I am doing. Thanks in advance.


Solution

  • Just wondering, have you thought about maybe dimming the screen to the absolute minimum? Maybe changing the color to black if you really don't want anything to be visible?

    Here's the issue - according to Google Glass TOS, you can't actually turn off the screen while an app is running, so even if you find some hacky way to do it, you aren't supposed to. I've been having this issue with my app as well.

    The solution for me (my issue was that battery was being eaten unbelievably quickly) was to use this code:

    To dim the screen (even though it says 0f, it is still a tiny bit lit)

    WindowManager.LayoutParams lp = getWindow().getAttributes();
    lp.screenBrightness = 0f;
    getWindow().setAttributes(lp);
    

    To go back to full brightness:

    WindowManager.LayoutParams lp = getWindow().getAttributes();
    lp.screenBrightness = 1f;
    getWindow().setAttributes(lp);
    

    Then if you want to hide what's on the screen, you could just add a black box over everything in your layout and have it set to android:visibility="gone" until you want to dim the screen, then set the box's visibility to visible and back to gone once you want the screen to turn on again and you brighten it.

    In case you want to use the brightness that the person had before they opened the app instead of setting the brightness of the screen to maximum, you can use this code in your onCreate to get the original brightness so you know what to set it to later:

    int previousScreenBrightness = android.provider.Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS);
    

    Also, set this flag at the top, so the app doesn't dim/turn off on its own over time:

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    

    I hope this helps. Good luck!