Testing Location-Aware Android Apps on an Emulator

May 26, 2016 at 5:33 pm 1 comment

Tricky Android Emulator SetupGet Last Location

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

Android SDK Level 23 AVD Packages

Once you’ve downloaded the packages you need, then you can open the Android Virtual Device (AVD) Manager and create a new AVD (emulator).

  1. Click the “Create” buttonAVD Manager create button
  2. 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 GPUCreate new AVD

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,Map 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”.

AVD Settings, Location Dialog

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:

Happy location-aware app testing!

 

Advertisements

Entry filed under: Android, Mobile, Programming. Tags: , , .

Testing iOS Apps on Hardware Devices The Google Play Services APIs for Android

1 Comment Add your own

  • […] 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 […]

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Bird’s Bits

Computers, software & the Internet

Recent Posts

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 41 other followers


%d bloggers like this: