How to Use Wi-Fi and Geolocation Services in the Android Simulator on a Mac

• ~500 words • 2 minute read

Adventures in using the Android simulator

Android

Recently I've been using Appcelerator's Titanium to create cross-platform mobile applications for some personal and semi-professional projects. Testing my work out in iOS has been very straightforward whether I'm firing it up in the simulator or loading it on my iPhone. Because I don't have an Android device I'm reliant on the simulator that comes with the Android SDK to test out my applications there. So far, applications that don't rely on any of the phone's special features were easy to test and ran fine, as the apps were basically static content. However, I immediately ran into hurdles trying to test an app that tried to, of all things, load a remote webpage and make use of the phone's geolocation service - two things that seemed like relatively basic smartphone features.

Here were the problems and workarounds:

No Internet Connection?

This was the most baffling and frankly, the dumbest, both in terms of how easy it was to solve and that this issue even exists. My computer was connected via wifi and the iPhone emulator was able to use this connection without any problems. The Android emulator couldn't see the Internet connection at all and said I was disconnected. I exhausted my knowledge of four-letter nautical jargon before discovering this trick:

Disable your LAN. That's it. It now works.

This might not be a common setup, but my LAN port on my laptop is almost never used, though it's still enabled. I've never had any issues come from this until now. Evidently the Android emulator will look at this connection first. If it can't find any connection there, it assumes you're disconnected. There might be a very good reason it's setup this way, and maybe there's some obvious documentation that accompanies the Android SDK that I've managed to miss, but it seems like a really strange oversight to me.

No Geolocation?

All of the applications you run in the iPhone simulator are automatically fed bogus geolocation information. Unless you live in Cupertino, CA. In that case, it's still technically bogus but you might not ever notice. Anyhow, this works well enough for simulator testing.

With Android you can set it up to function similarly, but it requires a little bit of command line tinkering. After you have the Android simulator running, open up the Terminal and enter:

telnet localhost 5554

Then, after that's connected:

geo fix 45.52304 -122.640155

Obviously use whatever latitude and longitude pairing you need. Your apps on the Android simulator should now be receiving the dummy geolocation info. This hurdle didn't bother me so much as the other one, but it was not immediately obvious how to resolve the issue without a little Googling.

Caveats

I'm testing Android 2.2 on a Mac and can't verify whether or not these issues exist on other platforms or the latest version of Android which is 2.3 at the moment. It's possible there are other things particular to my setup that are creating some of these issues. The fact that I found other people experiencing these issues however leads me to believe these issues are either common and/or just a poorly documented aspect of working with the Android simulator.