Place Picker Automatically close after launch
Asked Answered
L

6

13

I want to show place picker so that user can choose location of his/her own choice. But place picker child activity automatically closes after launch. I've check the API key multiple times and other permissions, everything is correct. Here is all the code. Please help!

task_location.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                PlacePicker.IntentBuilder intentBuilder = new PlacePicker.IntentBuilder();
                Intent intent = intentBuilder.build(NewTaskActivity.this);
                // Start the Intent by requesting a result, identified by a request code.
                startActivityForResult(intent, 123);


            } catch (GooglePlayServicesRepairableException e) {
                GooglePlayServicesUtil
                        .getErrorDialog(e.getConnectionStatusCode(), NewTaskActivity.this, 0);
            } catch (GooglePlayServicesNotAvailableException e) {
                Toast.makeText(NewTaskActivity.this, "Google Play Services is not available.",
                        Toast.LENGTH_LONG)
                        .show();
            }
        }
    });

And here is the menifest file.

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    tools:replace="android:icon">

    <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="AIzaSyAjM9hWUXm8vlABqFbM_fJfQgIFli8HP1E"/>
Levee answered 25/5, 2015 at 8:39 Comment(0)
L
10

After A lot of debugging i solved it myself. The problem was package name..Android studio manage package name by itself on project creation. I change the package name in manifest and it was working perfectly fine. but when i get API key from google developers console for place picker, place picker automatically closes without a single character of error.

Then I change the package name by going into -> Module Settings -> Flavors and change the Application ID and it fix the problem.

Levee answered 26/5, 2015 at 13:28 Comment(4)
How do you get to Module Settings?Mesenchyme
Right Click on your project, and click the second last option from the list. e.g Module Settings OR simply press F4.Levee
Thanks, couldn't find the problem for at least a few hours.Hoye
Thanks @ZeeshanAhmed. IDoukhobor
S
27

Please check the logcat of your app for 'PLACES_API_ACCESS_NOT_CONFIGURED' message. If this is the case, enabling the Google Places API for Android in your Google Developer Console for this project should solve your problem.

Slab answered 26/5, 2015 at 12:21 Comment(2)
Thanks, Its worked for me after i enableGoogle Places API Web Service API in Google Api developer consoleTrapeze
i am getting same issue i had enable place api already but getting still issue is there any solution?Picard
L
10

After A lot of debugging i solved it myself. The problem was package name..Android studio manage package name by itself on project creation. I change the package name in manifest and it was working perfectly fine. but when i get API key from google developers console for place picker, place picker automatically closes without a single character of error.

Then I change the package name by going into -> Module Settings -> Flavors and change the Application ID and it fix the problem.

Levee answered 26/5, 2015 at 13:28 Comment(4)
How do you get to Module Settings?Mesenchyme
Right Click on your project, and click the second last option from the list. e.g Module Settings OR simply press F4.Levee
Thanks, couldn't find the problem for at least a few hours.Hoye
Thanks @ZeeshanAhmed. IDoukhobor
N
2

Make sure that Google Places API is enabled for the API key that you are using in Google API console. For me, I am using the same API key that I use for maps. I just enabled the same key for places api also. That solved my problem. Use this link to access the Google console: https://console.developers.google.com/flows/enableapi?apiid=placesandroid&reusekey=true

Nutt answered 9/4, 2018 at 14:52 Comment(0)
C
1

Solved problem by just changing the API key

You can create a new key from here

Core answered 10/8, 2017 at 9:32 Comment(0)
P
1

Instead of enabling the places API, Enable the places SDK for android. Worked for me. Good Luck :)

Partly answered 4/9, 2018 at 6:34 Comment(0)
H
1

Enable both places API as well as Places sdk

Haase answered 12/1, 2019 at 7:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.