Android PlacePicker closes 2 seconds after launch
Asked Answered
P

3

8

Unfortunately I couldn't find an answer at Android Place Picker closes immediately after launch. For me the PlacePicker launches, shows location as Unknown and then returns with the resultCode 2.

To reaffirm some truths: My app has two activities so far. The first activity is a map, which works fine so far; no problem there. The second activity has a button that allows the user to launch the PlacePicker. The fact that the first activity launches the map with no problem should reinforce to you the reader that my manifest is fine and that my Google Api Console has the correct data. So that leaves me with: what am I doing wrong? I am using the exact example as https://developers.google.com/places/android-api/placepicker. In fact here is my code

try {
  IntentBuilder builder = new IntentBuilder();
  startActivityForResult(builder.build(this), REQUEST_PLACE_PICKER);
} catch (GooglePlayServicesRepairableException e) {
  e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
  e.printStackTrace();
}

and then

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (RESULT_OK != resultCode) {
        Log.d(TAG,"bad result: "+resultCode);
        return;
    }
    if (REQUEST_PLACE_PICKER == requestCode) {
        Place place = PlacePicker.getPlace(data, this);
        String toastMsg = String.format("Place: %s", place.getName());
        Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show();
    }
}

and here is my complete log

 D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
 W/IInputConnectionWrapper: showStatusIcon on inactive InputConnection
 D/SRIB_DCS: log_dcs ThreadedRenderer::initialize entered! 
 D/AddLocationActivity: bad result: 2
Portugal answered 2/1, 2016 at 22:24 Comment(1)
Facing same problem. Have you found any solution?Devisal
K
0

Please make sure you have added the sha-1 key to the google api console.

How to get SHA-1 fingerprint: https://developers.google.com/places/android-api/signup#debug-cert ideally you would add your debug key SHA-1 and your release key SHA-1 to the console so both keys are able to use the api.

You should go through the steps described on this page and make sure you don't skip anything: https://developers.google.com/places/android-api/signup#api-console

Koenig answered 19/6, 2017 at 8:18 Comment(0)
J
0

I solved this problem by signing in to my Google Developer Console. Then headed over to Api > Dashboard and then clicked the ENABLE APIS AND SERVICES.

Link to Google Developer Api Dashboard

Jarid answered 17/1, 2018 at 22:9 Comment(0)
C
0

Check API dashboard for your app. If you are not seeing API hits for "Places SDK for Android" API, probably the API is not enabled. If you see this API was hit, check the errors. If you see 403 errors, possibly you are using 1) a wrong Android key or 2) a wrong Application Restriction or 3) a wrong API restriction or a combination of these.

Cantle answered 8/10, 2018 at 7:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.