While attempting to put some power management features in place, I came upon the need to know if and when the screen on the device was turned off and turned back on again. Turns out there is are two handy intent broadcasts that you can listen for that suited my needs perfectly: Intent.ACTION_SCREEN_OFF and Intent.ACTION_SCREEN_ON.
"So I have a pair of google glass here if you want to play with it for the week, see what you can do".
This is how our weekly team meeting started on Monday. Needless to say I jumped at the chance, cleared my schedule and got my hot little hands on them the very next morning. I spent the next 3 days hacking together some little proof of concept applications to show at work. Glass development is easy to get into if you have previous Android development experience. It sits on top of the existing Eclipse tools and extends them via the Glass Development Kit (GDK).
There are plenty of resources out there to help get you started, so instead of duplicating those I figured I would share things that I had troubles with when I was starting out:
While creating a library that wraps up asynchronous http connection requests I wrote a handy helper function that takes an open HttpURLConnection and reads the resulting input stream into a String. I figured it was useful to me, so it may be useful to someone else as well. I continue on in my library to parse the String into either XML or JSON; this function simply returns a raw String for you to use as you please.
Like many applications, my current project required me to add the ability for a user to log out from a settings page. In my case, I wanted to user to be sent to HomescreenActivity on logout. I did not want the user to be able to use the back button once they have logged out, because, well... they logged out.
While writing up a unit test for a service I had written, I needed to parse out a JSON test string into a large JSON object. I found the best way to do this was to place the test data in a file located in the 'res/raw' folder (create this folder if your project does not include it already) and then read the file, and parse it as a JSON object.