问题
In my project PlacePicker
was working fine but today suddenly its closing immediately after launch with resultCode 2.
here is the logcat output
07-06 16:06:36.596 1023-20519/? W/Places﹕ e.a:638: gLocReplyElement
unsuccessful status: 1
07-06 16:06:36.596 1023-20519/? W/Places﹕ e.a:665: gPlaceQueryResult
unsuccessful responseCode: 26
07-06 16:06:36.596 21086-21708/? E/PlacePicker﹕
PLACES_API_QUOTA_FAILED
Any idea? what is the meaning of PLACES_API_QUOTA_FAILED
error code?
回答1:
Assuming you have the Place API for Android enabled and your API key is correctly configured in your manifest, this could also happen if you are missing your SHA-1 certificate fingerprint(s) in your developer console. So, make sure you have the following covered:
In the developers console make sure you have the API key generated for your android app and make sure the API key is entered in your manifest file. It should be a meta tag nested inside the application tag.
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.my.awesome.app"> <application> <meta-data android:name="com.google.android.geo.API_KEY" android:value="AIza..."/> ... other stuff </application> </manifest>
- On the same page as your API key, at the bottom, you need to enter the package name from your manifest and the certificates. While in development/debug mode you can use the certificate from the debug keystore supplied by the studio, however, for the release version you'd have to generate your own keystore.
To generate the keyhash for the debug mode:
keytool -exportcert -alias androiddebugkey -keystore C:\Users\{username}\.android\debug.keystore -list -v
Same command is used for the release version, but this time you'd need to point to your own keystore.
More info here
回答2:
See here for info on the error code... It might throw a better error by now, but that used to mean something is wrong with your certificate fingerprints in the API Console.
We were having a similar problem (PlacePicker
closing immediately with result code 2, except we did not have any relevant console output). We ended up fixing our issue by removing all fingerprints to get it working and then slowly adding security back:
- Remove all entries under "Restrict usage to your Android apps" on the page for your api key in the credentials section of the Google API console
- On the same key page, click "regenerate key" at the top (yes -- this was actually required for us @_@... you could try the old key again before doing this)
- Test your app with the new key
If PlacePicker
is now working, try adding security back in:
https://developers.google.com/maps/documentation/android-api/signup
Other info
Our devices were running Android API level 23 (Android 6.0)
Our app / module level
build.gradle
is using:compile 'com.google.android.gms:play-services-maps:9.0.0' compile 'com.google.android.gms:play-services-gcm:9.0.0' compile 'com.google.android.gms:play-services-location:9.0.0'
Our project level
build.gradle
is using:classpath 'com.google.gms:google-services:3.0.0'
```
回答3:
The Google Places API for Android enforces a default limit of 1 000 requests per 24 hour period. If your app exceeds the limit, the app will start failing.
You can find complete explanation here https://developers.google.com/places/android/usage
来源:https://stackoverflow.com/questions/31243930/google-placepicker-closes-immediately-after-launch-with-resultcode-2