I'm trying to use the Places API for Android in my project but it throws this exception.

Since it's deprecated I'm using the compatibility library that Google has set up but I cannot make it work, I've already enabled the Places API, set up an unrestricted API for it (just for testing purposes) and enabled billing. I also followed the documentation Google has enabled for the migration process.

Here's my gradle.app file:

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.google.android.gms:play-services-auth:16.0.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.google.android.libraries.places:places-compat:1.1.0'
    implementation 'com.android.support:multidex:1.0.3'
}

Here's my meta-data in the Manifest, it's snipped before closing the Application tag

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

The imports in the Fragment I'm using

import com.google.android.libraries.places.compat.Place;
import com.google.android.libraries.places.compat.ui.PlacePicker;

And the code I'm using

PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();

    Intent intent;
    try
    {
        intent = builder.build(getActivity());
        startActivityForResult(intent, REQUEST_CODE);
    }
    catch (GooglePlayServicesRepairableException e)
    {
        e.printStackTrace();
    }
    catch (GooglePlayServicesNotAvailableException e)
    {
        e.printStackTrace();
    }

public void onActivityResult(int requestCode, int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);

    if(requestCode == REQUEST_CODE && resultCode == RESULT_OK)
    {
        TextView newLocationText = v.findViewById(R.id.newAddress);
        Place place = PlacePicker.getPlace(data,v.getContext());
        String address = String.format("Place: %s",place.getAddress());
        newLocationText.setText(address);
    }
}

When I run the app I get this message in the logcat:

2019-04-22 00:31:50.114 2381-5745/? E/Places: Places API for Android does not seem to be enabled for your app. See https://developers.google.com/places/android/signup for more details.
2019-04-22 00:31:50.122 7584-7584/? E/Places: Place Picker closing due to PLACES_API_ACCESS_NOT_CONFIGURED
2019-04-22 00:31:50.312 2381-5745/? E/Places: Places API for Android does not seem to be enabled for your app. See https://developers.google.com/places/android/signup for more details.
2019-04-22 00:31:50.313 2381-5745/? E/AsyncOperation: serviceID=65, operation=SearchPlaces
OperationException[Status{statusCode=PLACES_API_ACCESS_NOT_CONFIGURED, resolution=null}]

1 Answers

0
Adeel Zafar On

Was facing the same issue, tried everything but nothing worked. And then I tried creating a new API key. This solution worked for me!