Android Programming The Big Nerd Ranch Guide by Bill Phillips, Chris Stewart, Kristin Marsicano (z-lib.org)

(gtxtreme123) #1

Chapter 33  Locations and Play Services


Your AVD emulator also needs to have a target OS version that supports the Google APIs. When you
create an emulator, you can identify these target OS versions because they will say “with Google APIs”
on the right. Choose one with an API level of 21 or higher and you will be all set (Figure 33.3).


Figure 33.3  Choosing a Google APIs image


If you already have a suitable emulator but you had to update your images through the SDK earlier,
you will need to restart your emulator for it to work.


Mock location data


On an emulator you will also need some dummy (or mock) location updates to work with. Android
Studio provides an Emulator Control panel that lets you send location points to the emulator. This
works great on the old location services, but it does nothing on the new Fused Location Provider.
Instead, you have to publish mock locations programmatically.


We here at Big Nerd Ranch love to explain interesting things in minute detail. After the debacle that
was Snipe Hunting: The Big Nerd Ranch Guide, though, we prefer to explain useful things. So instead
of making you type out this mock location code, we have written it for you in a stand-alone app called
MockWalker. To use it, download and install the APK at this URL:


https://www.bignerdranch.com/solutions/MockWalker.apk

Free download pdf