27

I am getting the following exception while trying out google places API to get likelihood places for Current Place in android.

Process: me.nabeelkottol.linkedinplaces, PID: 2995
 com.google.android.gms.tasks.RuntimeExecutionException: 
 com.google.android.gms.common.api.ApiException: 13: ERROR
 at com.google.android.gms.tasks.zzn.getResult(Unknown Source)
 at 
 me.nabeelkottol.linkedinplaces.MainActivity$1.onComplete(MainActivity.java:71)
 at com.google.android.gms.tasks.zzf.run(Unknown Source)
 at android.os.Handler.handleCallback(Handler.java:739)
 at android.os.Handler.dispatchMessage(Handler.java:95)
 at android.os.Looper.loop(Looper.java:148)
 at android.app.ActivityThread.main(ActivityThread.java:5417)
 at java.lang.reflect.Method.invoke(Native Method)
 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: com.google.android.gms.common.api.ApiException: 13: ERROR
 at com.google.android.gms.common.internal.zzb.zzz(Unknown Source)
 at com.google.android.gms.common.internal.zzbk.zzaa(Unknown Source)
 at com.google.android.gms.common.internal.zzbl.zzs(Unknown Source)
 at com.google.android.gms.common.api.internal.zzs.zzc(Unknown Source)
 at com.google.android.gms.common.api.internal.zzs.setResult(Unknown Source)
 at com.google.android.gms.location.places.zzm.zzao(Unknown Source)
 at com.google.android.gms.location.places.internal.zzx.onTransact(Unknown Source)
 at android.os.Binder.execTransact(Binder.java:453)

this is my code:

try {
      Task<PlaceLikelihoodBufferResponse> placeResult = mPlaceDetectionClient.getCurrentPlace(null);
      placeResult.addOnCompleteListener(new OnCompleteListener<PlaceLikelihoodBufferResponse>() {
        @Override public void onComplete(@NonNull Task<PlaceLikelihoodBufferResponse> task) {

          PlaceLikelihoodBufferResponse likelyPlaces = task.getResult();
          for (PlaceLikelihood placeLikelihood : likelyPlaces) {
            Log.i(TAG,
                String.format("Place '%s' has likelihood: %g", placeLikelihood.getPlace().getName(),
                    placeLikelihood.getLikelihood()));
          }
          likelyPlaces.release();

        }
      });
    } catch (SecurityException e) {
      e.printStackTrace();
    }

Here the line PlaceLikelihoodBufferResponse likelyPlaces = task.getResult(); is giving me the error.

I have created an API key for the android app by giving the package name and SHA-1 key for debug from Google API console. And enabled Google Places API for android in the libraries section. still its giving the same error. Dont know what is wrong with the implementation. Please help me.

There is an issue reported in github regarding this.

This is my app/build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "me.nabeelkottol.linkedinplaces"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.google.android.gms:play-services-places:11.6.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

This is my AndroidManifest.xml.

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="me.nabeelkottol.linkedinplaces">

  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
  <uses-permission android:name="android.permission.INTERNET"/>

  <application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:supportsRtl="true"
      android:theme="@style/AppTheme">
    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="My API Key here"/>

    <activity android:name=".MainActivity">
      <intent-filter>
        <action android:name="android.intent.action.MAIN"/>

        <category android:name="android.intent.category.LAUNCHER"/>
      </intent-filter>
    </activity>
  </application>

</manifest>
4
  • can you please post your build.gradle file. Commented Nov 21, 2017 at 11:10
  • @Dilip updated. pls check Commented Nov 21, 2017 at 11:19
  • have you added API key in your manifest file? Commented Nov 23, 2017 at 4:30
  • Ya I have added that in question. please see. Commented Nov 23, 2017 at 6:07

9 Answers 9

15
+50

Add the below code in manifest

 <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
Sign up to request clarification or add additional context in comments.

5 Comments

This doesn't fix the issue
@IgorGanapolsky what exactly are you getting in logcat window
@UmarAta This issue com.google.android.gms.common.api.ApiException: 13 is device specific. Your code does not fix the issue
Yes, I have and it does not fix the issue @UmarAta
can you describe what you did till now and what error you are getting in logcat @Vicky
9

I had the same issue, I was able to resolve it by enabling Google places Api from Google console and adding places api key. As soon as you enable the Places api, it will automatically ask you to add api key, just follow the instructions.

Then add the API key in your manifest file.

<application
    ...

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

</application>

Also, your emulator should have latest Google Play Services installed. Else use real Android device for testing.

1 Comment

Previously I had set my key as indicated here, then suddenly the search function stopped working (it may have had to do with my switching from the AutoCompleteActivity widget to the programmatic PlacesAutocompleteAdapter. So I had to recreate/obtain a new GCP key
5

You can see a discussion here about this issue. For me the problem occurred on the emulator but it was working on a physical device.

Comments

3

OK. I hope you didn't have to waste as much time as I did to find out this. But to get @Umar Ata 's answer working you need to put in both of the meta-data tags in your manifest file. So it should go like this.

<application>
...
<meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />

<meta-data
    android:name="com.google.android.geo.API_KEY"
    android:value="PASTE_YOUR_API_KEY_HERE" />
...    
</application>

And even after getting everything right it gave me error: PLACES_API_ACCESS_NOT_CONFIGURED 9003 which I got fixed by enabling Places SDK for Android and things finally got well.

After enabling Places API enable other additional APIs from inside the APIs tab.

7 Comments

Can you please clarify how to enable Place SDK for Android? When enabling APIs and querying for "Place SDK for Android", Google returns only "Places API", which keeps giving me the PLACES_API_ACCESS_NOT_CONFIGURED 9003 error. Thanks
@user1823280 after enabling Places API. Go to APIs tab from left navigation pane. Over there u can enable and disable certain other Additional APIs. Enable Places SDK for Android from there. I will add a screenshot in the answer.
Thanks for your reply. I had tried that, but the website returns the following error: "You do not have sufficient permissions to view this page. Tracking Number: 61..............82" This only happens when clicking on the "Places SDK for Android" APIs. Can I ask you if it works for you at the time of writing?
It seems that this occurs for everyone now, here the same question has been asked: stackoverflow.com/questions/54519374/…
I meant if it worked for you the creation of a new key with the "Places SDK for Android". I checked, and it is not possible anymore for anyone. Your app is working because it is using the "old" SDK (Places SDK for Android) and a key created before 29th of January 2019. The creation of a new key after such a date is now only possible if associated with the new Places SDK, that is, using the new dependency 'com.google.android.libraries.places:places:1.0.0'. Source: developers.google.com/places/android-sdk/client-migration
|
1

Please try following hope so it will be working.

1) please updated your \sdk\extras\google\google_play_services and try again.

2)If you are use proguard please excluded google classes from obfuscating like this in proguard-rules.pro:

-keep public class com.google.** {*;}

3) Versions of play-services libs should be equal, for example:

compile 'com.google.android.gms:play-services-maps:11.6.0'
compile 'com.google.android.gms:play-services-gcm:11.6.0'

4)I just had this issue but solved it by downgrading the gradle version like so:

Old, troublesome version:

 classpath 'com.android.tools.build:gradle:2.2.0-rc2'

Fixed version:

classpath 'com.android.tools.build:gradle:2.3.3'

and don't forget to add following dependency in project level gradle file.

 dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
        classpath 'com.google.gms:google-services:3.1.0'

    } 

1 Comment

Its a sample and I am running in debug mode without proguard. And I am using this gradle version com.android.tools.build:gradle:3.0.0
1

I also experienced this exception when location settings were turned off. Before making the API call please make sure that you have turned on the location services.

2 Comments

got the solution. see @Umar's answer.
If location services are turned off you will experience the same error. So just keep that in mind
1

Make sure you have added the following meta-data in your manifest file.

<application
    ...

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

</application>

Also check for any API restrictions in your Google API console. If you have enabled any API restriction to the API_KEY, then it will work only for the particular API. You have to add Places SDK for Android under API restrictions.

enter image description here

Comments

1

I just resolved this error by fixing my permissions on device. I had requested ALLOW_FINE_LOCATION when I was supposed to request ALLOW_BACKGROUND_LOCATION. Just thought I would drop this in here so that people are aware that it's possible that this error has nothing to do with your API key. "Exception 13" appears to be a catch-all of some kind.

Comments

0

Well in my case both com.google.android.gms.version and com.google.android.geo.API_KEY were already added in manifest. Why this error occurred because i switched my project into a new system the sha1 key didn't matched from the list.

What i did to resolve this error is: I have generated new SHA1 from my new system and added this SHA1 in under

credentials=> API Key=> then Add package name and SHA1

of Places SDK for Android

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.