Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 535
Bastian Nanchen Avatar asked Nov 17 '16 14:11

Bastian Nanchen


People also ask

How Use Google places Autocomplete Android?

The autocomplete widget is a search dialog with built-in autocomplete functionality. As a user enters search terms, the widget presents a list of predicted places to choose from. When the user makes a selection, a Place instance is returned, which your app can then use to get details about the selected place.

Is Google places API free for Android?

The Places SDK for Android uses a pay-as-you-go pricing model. Places SDK for Android requests for the Places SDK for Android are billed by SKU. Along with the overall Google Terms of Use, there are usage limits specific to the Places SDK for Android.

How do I test Google places API?

Go to the Google Developers Console. Create or select a project. Click Continue to Enable the API. Go to Credentials to get a Server key (and set the API credentials).


2 Answers

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

like image 171
Bastian Nanchen Avatar answered Sep 22 '22 15:09

Bastian Nanchen


Change the API Key solved my problem.

You can generate new key from here

like image 26
Android Dev Avatar answered Sep 22 '22 15:09

Android Dev