5
votes

I'm trying to get the last known location in my Android Emulator from Android Studio by following this tutorial https://developer.android.com/training/location/retrieve-current.html

However, the callback method onConnectionFailed is called with error code: 2. When I show the error dialog in my emulator, it says:

Update Google Play Services

{app_name} won't run unless you update Google Play services.

UPDATE

when I click UPDATE button, I got an error message:

E/SettingsRedirect﹕ Can't redirect to app settings for Google Play services

I think the problem is because Google Play services is not included in the emulator. I tried following the answer here too Android Studio with Google Play Services, but it didn't work.

It says on Google documentation:

To test your app when using the Google Play services SDK, you must use either:

1.) A compatible Android device that runs Android 2.3 or higher and includes Google Play Store.

2.) The Android emulator with an AVD that runs the Google APIs platform based on >Android 4.2.2 or higher.

Can somebody tell me how to do point 2 ? My AVD is Nexus 5 API 22 x86

1

1 Answers

1
votes

Here's the version chart 4.2.2 means it should API level 17 and up. So your AVD should be fine. Alternatively, you can download Google Play Services APK and install it through ADB shell. See this answer for more information.

However, even if the Play Services issue is solved, you can not get location updates in an emulator since it does not have GPS hardware. You can simulate location behavior through geo command as described here.