1

I have Implemented PlacePicker in my Application. Its working fine in test cases. But the same thing is not working in Signed APK. I dont know how to fix this issue and so far googling not helped me. Seeking some help here.

Code Part

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mButton = (Button) findViewById(R.id.mButton);
    mTExt = (TextView) findViewById(R.id.mTExt);

    mButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
                startActivityForResult(builder.build(MainActivity.this), PLACE_PICKER_REQUEST);
            } catch (GooglePlayServicesRepairableException e) {
                e.printStackTrace();
            } catch (GooglePlayServicesNotAvailableException e) {
                e.printStackTrace();
                Log.e(TAG, e.getMessage());
            }
        }
    });
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == PLACE_PICKER_REQUEST
            && resultCode == Activity.RESULT_OK) {

        final Place place = PlacePicker.getPlace(this, data);
        final CharSequence name = place.getName();
        final CharSequence address = place.getAddress();
        String attributions = (String) place.getAttributions();
        if (attributions == null) {
            attributions = "null";
        }
        mTExt.setText("Name: " + name + "\n Address: " + address);

    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}

AndroiManifest.xml

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

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <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="Here I entered my API key" />

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

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
Alex Chengalan
  • 8,211
  • 4
  • 42
  • 56
  • 2
    You need to add your release keystore sha1 fingerprint to your API key. You can also use separate API keys for debug and release, see here: http://stackoverflow.com/questions/30559602/android-studio-google-map-still-blank-on-real-android-device – Daniel Nugent Mar 10 '16 at 15:17
  • There is no subfolders `debug` and `release` and also no `google_maps_api.xml` – Alex Chengalan Mar 10 '16 at 16:09
  • Yes, they get added automatically when using the wizard, but they won't be there if you didn't use the wizard. For you, the easiest thing to do would be to add both the debug and release sha1 fingerprints to the one API key, then you can keep the API key directly in the manifest as you have it now. – Daniel Nugent Mar 10 '16 at 16:11
  • how can I do that. I have already created API key in Google Developer Console and added in my manifest as u can see in the question, and its working fine when compiling from my computer. But if I install the signed apk , the the place picker just show and closes without any error/error log. – Alex Chengalan Mar 10 '16 at 16:17
  • 1
    Use the keytool command line tool to get the sha1 fingerprint of your release keystore. Then, add that sha1 fingerprint to your existing API key in the developer console. – Daniel Nugent Mar 10 '16 at 16:34
  • 1
    For more info on getting the release keystore sha1 fingerprint, see here: http://stackoverflow.com/a/30462918/4409409 – Daniel Nugent Mar 10 '16 at 17:03
  • Thanks! your comments guided me to the correct path. :) – Alex Chengalan Mar 12 '16 at 10:40

0 Answers0