Bastian Nanchen
Bastian Nanchen

Reputation: 732

Google Places API Android: Autocompletion closes too quickly

I added Place Autocompletion to my android app. When I click a button (chooseLocationButton) it opens the Autocomplete widget correctly. The problem is when I want to write a name in the search field. Directly after clicked on the first keystroke, the Autocomplete widget close and the research is not done. Here it is what it is written in the Run console:

W/IInputConnectionWrapper: reportFullscreenMode on inexistent InputConnection
W/IInputConnectionWrapper: finishComposingText on inactive InputConnection

Here it is the code:

AutocompleteFilter.Builder a = new AutocompleteFilter.Builder();
    try {
        final Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN)
                .setFilter(a.setTypeFilter(AutocompleteFilter.TYPE_FILTER_REGIONS).build())
                .build(this);
        chooseLocationButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                startActivityForResult(intent, PLACE_AUTOCOMPLETE_REQUEST_CODE);
            }
        });
    } catch (GooglePlayServicesRepairableException e) {
        e.printStackTrace();
        // TODO handle exception!
    } catch (GooglePlayServicesNotAvailableException e) {
        e.printStackTrace();
        // TODO handle exception! Toast?
    }

Of course I have enabled Google Places android API and Google Map android API in the Google Developer Console. Also I have added the API key to the AndroidManifest.xml like that:

<meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />

In the log I observe this:

BasicNetwork.performRequest: Unexpected response code 400 for https://www.googleapis.com/placesandroid/v1/getAutocompletePredictions...

Followed by:

[67738] BasicNetwork.performRequest: Unexpected response code 403 for https://www.googleapis.com/placesandroid/v1/getAutocompletePredictions?key=...11-17 21:02:01.207 1053-1543/? E/Places: PLACES_API_INVALID_APP

In the Run Log of Android Studio I have: PLACES_API_KEY_EXPIRED

I hope somebody can help me.

Thank you.

Upvotes: 6

Views: 7575

Answers (3)

Hardik Lakhani
Hardik Lakhani

Reputation: 1564

Change the API Key solved my problem.

You can generate new key from here

Upvotes: 2

Bastian Nanchen
Bastian Nanchen

Reputation: 732

The problem was solved when I noticed that Google had created an .xml file for the API key and that created a conflict with the API that I put in the string.xml

Upvotes: 2

AndrewR
AndrewR

Reputation: 10889

It does sound like a key problem. Things to double-check:

  • The key is an Android key, not a web key.
  • The package name restrict on the key actually matches the package name of your app, and it is signed correctly.
  • You haven't exceeded the 1000 requests/day limit.

Upvotes: 0

Related Questions