Testing Location-Aware Android Apps on an Emulator
May 26, 2016 at 5:33 pm 1 comment
Tricky Android Emulator Setup
I found that testing apps that use the Android Fused Location Provider on an emulator
can be a bit tricky! (But, as a software developer, doesn’t every new thing you try turn out to be tricky?)
You need Google Play Services to Access Location Data
The Fused Location Provider is one of the APIs provided by Google Play Services. If you are creating a location-aware app, Google recommends that you use the this API rather than the older android.location API. In order to test your app in an emulator, you will need to have Google Play Services installed. The default Google Android Emulator images don’t include Google Play Services, but it is available and you can include it when you create an AVD (Android Virtual Device, aka emulator).
Watch a video of me using this post to set up an emulator:
http://screencast-o-matic.com/watch/cDhuruiixn
Setting up an Emulator with Google Play Services
First you need to download the right SDK packages using the Android SDK Manager. To set up an emulator that is running Marshmallow, API level 23, you’ll need the packages shown in the list below. (I’m assuming you have installed Intel HAXM and are using the x86 system images which are 10x faster than the ARM images)
- SDK Platform
- Intel x86 Atom_64 System Image
- Google APIs Intel x86 Atom System Image
- Google APIs
Once you’ve downloaded the packages you need, then you can open the Android Virtual Device (AVD) Manager and create a new AVD (emulator).
- Click the “Create” button
- Enter the following in each of the fields:
- AVD Name: Whatever you want to call it
- Device: Select one that suits you
- Target: Android 6.0 – API Level 23
- CPU/ABI: Google APIs Intel Atom (x86_64)
- Skin: whatever you like or “No skin”
- Memory Options: RAM: 2048, VM Heap: 384
(The VM Heap size depends on the device you are emulating. For a Nexus 5, it’s 256; for a Nexus 6, it’s 384.) - Cameras, Internal Storage, SD Card: defaults
- Emulation Options: check Use Host GPU
Testing Your Location-Aware App on the Emulator
The first time you start your emulator, it will take a while to come up; maybe a few minutes- depending on how fast your machine is.
You can simulate testing your own app by running the Google Maps app. You can skip the sign-in if you like. Click on “Show your location” button, you will get a dialog requesting you to enable “enhanced accuracy”. You need to select “yes”. You will notice that the map didn’t zoom to your location. That’s because the emulator doesn’t automatically send a response to a location request. You have to manually send the location response. You do that by opening the settings dialog, selecting the “Location” tab, and clicking “Send”.
If you click the “Show your location” button and then quickly click the “send” button, the map will zoom in and show you the Googleplex, that’s the default latitude and longitude in the location dialog. (I changed mine, so it’s not showing the default location).
BTW, double-clicking and dragging up or down will zoom in or out on the map.
You can test your own app the same way. Just remember that location requests won’t get an automatic response. You need to generate the responses by clicking the “send” button, or by uploading a file for GPS data playback and clicking the play button.
Other Emulators
Of course, you have alternatives when it comes to Android Emulators. Here are some of those other emulators and links to instructions on how to set up Google Play Services on those emulators:
- Visual Studio Android Emulator (Windows only)
This emulator comes with Visual Studio. The free Visual Studio Community Edition supports Android development through the free Xamarin.Android add-in. Here are instructions for installing google play services in the Microsoft Visual Studio Android emulator. - Xamarin Android Player (OS-X and Windows)
This emulator is still in the alpha stage, but works quite well for most things. There is a Windows version, but it may not continue to be developed. Since Microsoft bought Xamarin, they seem to want us to just use Visual Studio for Android and iOS development on Windows but use Xamarin Studio on OS-X. There is a free download for the Xamarin Android Player. And these are the instructions for adding Google Play Services to the Xamarin Android Player. - GenyMotion (OS-X and Windows)
There is a freemium version for personal use. Here are instructions for installing Google Play Services.
Happy location-aware app testing!
Entry filed under: Android, Mobile, Programming. Tags: Android, Mobile, programming.
1. Using the Android Fused Location Provider | Bird's Bits | May 27, 2016 at 4:10 pm
[…] have enough code written now to test the app. But first you need to install Google Play Services in your emulator. When you run the app, and click the “Get last location button”, you should see a […]