简体   繁体   中英

Android Studio Emulator Google Play Services

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM