Categories
Google Glass

Debugger this! Debugging an Android Service

I recently found out that I couldn’t hit any breakpoints in an Android Service I was developing. I found that this was easily sorted by adding the following line:

android.os.Debug.waitForDebugger()

This approach was suggested on various websites including StackOverflow and HelloAndroid amongst many. Great.

I found out much later than when I ran the code “in the wild” i.e. in a production environment unattached to a debugger, my application was failing.

Long story short, this is caused by the waitForDebugger() call, which will cause any code following your invocation to not be executed if there is no debugger.

I suppose I should have realised, but I had assumed that maybe the runtime or the call itself would be clever enough to know whether the application was in debug mode at all, and ignore it if it wasn’t.

But thankfully, we can do that:

if (android.os.Debug.isDebuggerConnected)
{
    android.os.Debug.waitForDebugger()
}

So I’d recommend this is the approach you take over having to remember to take that call out.

Categories
Google Glass

Using Gradle from behind a proxy

By default Android Studio uses Gradle to build Android projects. This means Android Studio always needs a connection to the internet to check for and retrieve dependencies. If you’re developing from behind a proxy (as I am) then you’ll have to explicitly tell Gradle the proxy details to allow it to connect to its servers.

Steps to fix

  1. Navigate to the “.gradle” folder in your user directory (e.g. C:\Users\bob\.gradle)
  2. Create a “gradle.properties” file
  3. Edit the file to have the following contents (replacing your own values)
systemProp.http.proxyHost=<proxy_host>
systemProp.http.proxyPort=<port>
systemProp.http.proxyUser=<user>
systemProp.http.proxyPassword=<password>
systemProp.http.nonProxyHosts=*.nonproxyrepos.com|localhost

Gradle should then succeed on the next build.

Note – thanks go to Steve Hanson for these steps.

Update 08 Dec 2014 – As of the update to Android 1.0, these steps are not enough! I’ve documented the new definitive list in this post.

Categories
Technology

Google Glass, Eye Love You

Having done a bit of research on what apps people are starting to develop for Google Glass, I stumbled on word of a recent Glass Hackathon where, among other things, an app was built to measure attraction:

It uses an eye tracker, mounted on the Glass frame, to measure the pupil dilation of the wearer. The idea is to measure someone’s arousal, giving an instant measure of how attracted they are to the person they are looking at.

Initially I misread this and thought it was built to track pupil dilation in someone else’s eyes, not the wearer’s. The thought of the proximity you’d have to have between your face and that of the person you’re analysing amused me greatly.

It did remind me of the sort of advice you see bandied around on the internet – “Dude if her pupils are dilating, she’s totally into you”. Dude, if you’re staring into each other’s eyes close enough to observe the dilation of her pupils, she’s probably into you.

Attraction

 

Lastly, on a more serious note, tracking the wearer’s pupil dilation has already been patented by Google, with some people suggest it could be used to gauge your emotional response to advertising.