Google Place Picker widget not working - android

According to This Official Post
I'm following below steps to integrate Place Picker UI dialog with Map.
launcher code
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST);
inside onActivityResult()
if (requestCode == PLACE_PICKER_REQUEST) {
if (resultCode == RESULT_OK) {
Place place = PlacePicker.getPlace(this, data);
tvChooseLocation.setText(place.getName());
}
}
I have added all permissions & API_KEY in Manifest file
Problem is I am not able to select location from Place Picker dialog.
Select button is disabled by default.

I have solved this so I don't quite know which one of these steps solves it
In console.developer.google.com
I enable Places API and Maps API, and download the json from here.
Also, get the API key from Credential page.
In Android Studio
In manifest, add in between <application> ... </application>
<meta-data android:name="com.google.android.geo.API_KEY" android:value="YOUR_KEY_FROM_CREDENTIAL_PAGE"/>
In onCreate(), add this (though I don't quite sure this is needed or not)
private GoogleApiClient mGoogleApiClient;
mGoogleApiClient = new GoogleApiClient
.Builder(this)
.addApi(Places.GEO_DATA_API)
.addApi(Places.PLACE_DETECTION_API)
.enableAutoManage(this, this)
.build();
Everything else just follow the tutorial in here. Also, I tested it in release version. If you still have the same problem, try make a release one. I failed to get the location in emulator but it work just fine in my phone.
Hopefully this can help anyone in the future.

Try enabling google places api from google developer console
Link to console
--Wanted to comment though but do not have permission.

Related

Google place picker closes immediately after launch

This is a problem that I've been stuck for weeks, but still, I can't solve it. My friend's google place picker worked, but not mine (even though we have the same code).
But once in 20-30 tries, it opens the UI lets me have a look at nearby places around my location (but that's a very very rare case).
I've done everything I possibly could.
1) I've enabled Google Places API for Android and generated my API key. I've also added my SHA-1 certificate fingerprint and package name.
2)I've imported everything related to google play services that I could in gradle.
implementation 'com.google.android.libraries.places:places-compat:1.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:support-vector-drawable:26.+'
implementation 'com.google.android.gms:play-services-places:16.0.0'
3)I've also given my API key inside of meta-data in my application tag in AndroidManifest.xml
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_place_api" />
</application>
4)I've copied the exact code that I got from Place-picker documentation site https://developers.google.com/places/android-sdk/placepicker
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
try {
startActivityForResult(builder.build(maps.this), PLACE_PICKER_REQUEST);
} catch (
GooglePlayServicesRepairableException e) {
e.printStackTrace();
} catch (
GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}
#Override
protected void onActivityResult ( int requestCode, int resultCode, Intent data){
if (requestCode == PLACE_PICKER_REQUEST) {
if (resultCode == RESULT_OK) {
Place place = PlacePicker.getPlace(data, this);
String toastMsg = String.format("Place: %s", place.getName());
Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show();
}
}
5)I've even enabled billing for my project, where Google charged me Re 1.
This is very important for my project, so please someone help me. I beg of you.
Edit: I'm getting some kind of error in my logcat too:
Place Picker closing due to PLACES_API_ACCESS_NOT_CONFIGURED
the Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
2019-05-12 08:07:57.106 2818-3899/? E/Volley: [171] BasicNetwork.performRequest: Unexpected response code 403 for https://www.googleapis.com/placesandroid/v1/placePicker?key=AIzaSyCz-bC6nazJur-gHEgVoZMujFDyVvs2n9M
2019-05-12 08:07:57.110 2818-20254/? 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-05-12 08:07:57.112 2818-20254/? E/AsyncOperation: serviceID=65, operation=PlacePickerQuota
EDIT#2: Is there any solution to this? Please answer me.
You seem not to have enabled place API, below is the link to the steps to get that done.
https://support.google.com/googleapi/answer/6158841?hl=en
if you check your logcat well enough, maybe by selecting the types of log you want to see, you can select Error instead of verbose, then you will see the error like below
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.
I believe the issue is related to the deprecated version of Places SDK for Android. You have the following statement in gradle
implementation 'com.google.android.gms:play-services-places:16.0.0'
This refers to the Google Play version of Places SDK, that was deprecared. In order to use new static library of Places SDK the gradle should use
implementation 'com.google.android.libraries.places:places:1.1.0'
Please double check all steps mentioned in the documentation of new library to be sure that you migrated to new version correctly:
https://developers.google.com/places/android-sdk/start
I hope this helps!

Google Drive API Initialization and First Time Use Issue

I have an Android application I am writing that uses the Google Drive API. I am using the Drive.SCOPE_APPFOLDER to have a private location to put my application data, if the user chooses to sync the app with their Google drive. For the most part everything works fine and I can sync contents to the Google drive. However, I am having major difficulties on the initialization front. First of all, I can recognize when the users has not used the Google drive and launch the sign in activity. Here is how I build my google sign in client. I don't actually think I need the .requestEmail() and .requestProfile() but it is there for now.
private GoogleSignInClient buildGoogleSignInClient(AppCompatActivity activity) {
GoogleSignInOptions signInOptions =
new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestScopes(Drive.SCOPE_APPFOLDER)
.requestEmail()
.requestProfile()
.build();
return GoogleSignIn.getClient(activity, signInOptions);
}
To recognize that the user has not signed into to Google Drive or used the Drive with the app I have the following code.
private void initGoogleClient() {
mGoogleSignInAccount = GoogleSignIn.getLastSignedInAccount(getActivity());
if (mGoogleSignInAccount == null) {
launchSigninActivity(getActivity());
} else {
mDriveResourceClient = Drive.getDriveResourceClient(getActivity().getApplicationContext(), mGoogleSignInAccount);
//.... doing stuff here that works fine
}
}
To launch the sign in activity I have the following code.
private void launchSigninActivity(AppCompatActivity activity) {
mGoogleSignInClient = buildGoogleSignInClient(activity);
Intent signinIntent = mGoogleSignInClient.getSignInIntent();
activity.startActivityForResult(signinIntent, SIGNIN_INTENT_CODE);
}
Now the sign in activity gets launched just fine and users can sign in to their Google account. However, any time the Google UI is presented to sign in the user, the error code, code=8 INTERNAL_ERROR is thrown. If the user has previously signed into their drive account before using my app, the error code 8 is not thrown.
public void handleSignIn(int requestCode, int resultCode, Intent data) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
try {
mGoogleSignInAccount = task.getResult(ApiException.class);
mDriveResourceClient = Drive.getDriveResourceClient(getActivity().getApplicationContext(), mGoogleSignInAccount);
//... other App specific stuff
} catch (ApiException e) {
Log.w(TAG, "************* signInResult:failed code=" + e.getStatusCode());
}
}
(onActivityResults() in my activity calls the code above) The getActivity() method just returns the activity that handled the onActivityResults().
The second issue I have noticed is that there are some timing issues when using the GoogleResourceClient on first time use with my app. The first few times I try to read the drive, it seems to be empty, but at some point the remote files show up. I have not characterized how long it takes before reads find files but it seems that the drive API is returning before any calls to the remote drive on initial/first time app use calls.
These issues only happen on first time use of the Android app. All subsequent launches of the app run smooth. Does anyone have any ideas about these issues?
Google had deprecated this library. Move the the Google Drive REST API.

How do i ensure I always get the new google games playerId instead of the legacy id?

While my app was in alpha and unpublished, anytime a user signed in to google play games i would get their id Games.Players.getCurrentPlayer(mGoogleApiClient).getPlayerId() and it would return an id in this format
g07610263060548408114
Now that I am in an open beta however, using the same call gives me an id in this format
117053902313732480537
(I'm not saying that the progression from alpha to beta or that i published caused this, but it's when i started noticing a change.)
From reading a few issues in the unity plugin project on github,
Native Android Google+ User ID different than using Unity Plugin #1277 and the issue it references, it seems that the second version of the id i'm now getting is an outdated version that is linked to the user's google plus account. The new version (with the prefixed g) is supposedly available so that the players don't need to have a google plus account in order to play my game. See this post for the google announcement about the replacing of ids. It sounds like the unity plugin returns the new id while the native android libraries do not.
So my question is, why in the newest version of google play games services (10.2.1) is the id that i get for my users the legacy id? And how can i get the new version-- the one that is the same as the participant ids in a match?
I've tried using google's new sign in api's but that also gives me the legacy id. Even for users where before i was getting the new id format.
I could use this legacy id everywhere and it would at least be consistent, however the only id i get from
turnBasedMatch.getParticipants.get(0).getPlayerId() is the new id, so i would never be able to map the two. I want to use the new id, but i can't get it anymore for new users.
My activity currently extends BaseGameActivity
and this is some of the code i use to initialize the client before i tried the new sign in
mPresenter = GameSetupPresenter.getInstance(getApiClient());
getApiClient().registerConnectionCallbacks(mPresenter);
getApiClient().registerConnectionFailedListener(mPresenter);
#Override
public void onSignInSucceeded() {
Games.Players.getCurrentPlayer(mPresenter.getGoogleApiClient()).getPlayerId();
}
This line where i get the playerId either returns the id in the legacy or the new format.
Using the new sign in process my code looks like this:
GoogleSignInOptions options = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
.requestId()
.requestIdToken(getString(R.string.server_client_id))
.requestProfile()
.requestScopes(new Scope(Scopes.GAMES), new Scope(Scopes.PROFILE), new Scope(Scopes.PLUS_ME))
.requestServerAuthCode(getString(R.string.server_client_id), false)
.build();
mPresenter = GameSetupPresenter.getInstance(null);
GoogleApiClient client = new GoogleApiClient.Builder(this)
.enableAutoManage(this, mPresenter)
.addApi(Auth.GOOGLE_SIGN_IN_API, options)
.addApi(Games.API)
.build();
mPresenter.bindGoogleApiClient(client);
client.registerConnectionCallbacks(mPresenter);
client.registerConnectionFailedListener(mPresenter);
Intent intent = Auth.GoogleSignInApi.getSignInIntent(client);
startActivityForResult(intent, RC_SIGN_IN);
#Override
protected void onActivityResult(int request, int response, Intent data) {
super.onActivityResult(request, response, data);
if (request == RC_SIGN_IN) {
if(response == RESULT_OK) {
Games.Players.getCurrentPlayer(mPresenter.getGoogleApiClient()).getPlayerId();//returns different id's based on whether user was created before or after game was published.
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
result.getSignInAccount().getId();//returns legacy id
}
}
You can look at the samples in https://github.com/playgameservices/clientserverskeleton
One thing to be aware of is if you only use the games config and requestAuthCode(), there are no additional consent prompts for users.
The GoogleSignIn API does not use the games ID if you are requesting additional items and scopes. To get the Games specific ID use:
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
GoogleSignInAccount acct = result.getSignInAccount();
Log.d(TAG,"Legacy account = " + acct.getId());
Log.d(TAG,"Games Id:" + Games.Players.getCurrentPlayer
(mGoogleApiClient).getPlayerId());

android unable pick location from place picker

I am unable to pick the location from place picker.
It disables the select button when select place but when to search location and pick then it enable select button.
I am using play services version
com.google.android.gms:play-services-location:9.4.0
and com.google.android.gms:play-services:9.4.0
btn_locationSend.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
try {
startActivityForResult(builder.build(ChatThreadActivity.this),PLACE_PICKER_REQUEST);
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
switch (requestCode) {
case PLACE_PICKER_REQUEST:
Place place = PlacePicker.getPlace(this,data);
LatLng location = place.getLatLng();
String toastMsg = String.format("Place: %s", place.getName());
} }
If your problem is not solved yet. Enable Google Places API for Android in dev console.
It's because you didn't give permission to use Places on google maps. Just go to the link and enable Google Places API for Android.
It maybe a bit late but check out my answer to what sounds like the same problem (Disable select button while selecting location of anonymous location using Place picker google API in android)
Basically make sure that the API Key in your AndroidManifest.xml has the correct name. While com.google.android.maps.v2.API_KEY will work for the Maps API the Places API requires com.google.android.geo.API_KEY.
If you are using the Maps API then you can use the same key and both APIs will work using the latter kay name.
use this
<application>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="YOUR_API_KEY"/>
</application>
insted of this
com.google.android.maps.v2.API_KEY
The code looks fine. In fact, I tried re-running it and found no such observation; the SELECT button of the Use this location pop-up dialog was always enabled. However, when I manually disabled my Internet connection, the SELECT button became disabled. So, I believe, if your Internet connection is intermittent or has a problem, you might be able to observe the same thing.

Android Drive GooglePlayServicesUtil﹕ The specified account could not be signed in

I need to use the drive api to create a file with some content from my app, so I followed the "Getting Started" section from Drive api web page.
So I enabled the api on my developer´s console, created an OAuth client id as it says. (Can I use the api if I haven´t paid the 2$5 yet?)
On my settings activity on the onCreate method I'm doing:
googleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
I'm implementing the methods:
#Override
protected void onStop(){
getGoogleApiClient().disconnect();
super.onStop();
}
#Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(STATE_RESOLVING_ERROR, resolvingError);
}
#Override
public void onConnectionFailed(ConnectionResult connectionResult) {
if (resolvingError) {
// Already attempting to resolve an error.
return;
}else if (connectionResult.hasResolution()) {
try {
resolvingError = true;
connectionResult.startResolutionForResult(this,RESOLVE_CONNECTION_REQUEST_CODE);
} catch (IntentSender.SendIntentException e) {
getGoogleApiClient().connect();
}
} else {
GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), this, 0).show();
resolvingError = true;
}
}
#Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
if(requestCode == RESOLVE_CONNECTION_REQUEST_CODE) {
resolvingError = false;
if (resultCode == RESULT_OK) {
if(!getGoogleApiClient().isConnecting() && !getGoogleApiClient().isConnected()){
getGoogleApiClient().connect();
}
}
}
}
#Override
public void onConnected(Bundle bundle) {
Toast.makeText(this, "Success!!! :D :D", Toast.LENGTH_SHORT).show();
}
#Override
public void onConnectionSuspended(int i) {}
Then I call googleApiClient.connect(); on a button onclick method.
I'm getting the select account google drive dialog, select an account and press OK, and I'm getting this error on the connection result:
E/GooglePlayServicesUtil﹕ The specified account could not be signed in.
I searched over the web and cant find the cause of this problem.... maybe I'm doing something wrong on the developers's console... don't know...
UPDATE:
So i delete the project on Google developer´s console and create it again, i also add the Drive Api and enable it, i added a product name on authorization screen, and a new client id with my package name and sha1 id...
also update my manifest,
added to manifest tag:
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
to application tag:
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
to the activity tag where im doing the connection:
<meta-data
android:name="com.google.android.apps.drive.APP_ID"
android:value="id=<app id i took this id from developers´console>" />
<action android:name="com.google.android.apps.drive.DRIVE_OPEN" />
<data android:mimeType="application/vnd.google-apps.drive-sdk.<app id>" />
i also building a signed apk using the debug keystore to test my app. (on real device).
after all this the error is still rising...
My guess is that there is a problem with the setup you did at the Developer's Console. This discussion may be helpful. – qbix
hello, reading the discussion qbix mention above i just found the cause of my problem...
the default flavor at my project structure had an incorrect Application id, i just change it to my app package "com.xxxxx.yyyyy".
so i beleave when googleApiClient attempted to connect, find diferent package name at id client credencials and deny access....
now is working fine thanx....
Here's my usual checklist:
1/ get the APK in question, push it through an unzipper, like 7-zip. you'll find a folder META-INF with a file CERT.RSA. Get it.
2/ run 'keytool -printcert -file ......\CERT.RSA' and copy/save the SHA1 '11.22.33...99'
3/ get you package name (from manifest?) 'com.blabla.yourproject'
4/ open developers console 'https://console.developers.google.com/project'
5/ in your project, check:
Enabled APIs: drive API
Credentials: Package name: 'com.blabla.yourproject', Fingerprint: '11.22.33...99'
Consent Screen: Email: yourmail#gmail.com , Product Name: 'YourProject'
Good Luck
Pleas try to First normal Google account Login
mGoogleApiClient = new GoogleApiClient.Builder(this).
addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addScope(new Scope(Scopes.PROFILE))
//.addApi(Drive.API)
//.addScope(Drive.SCOPE_FILE)
.build();
In my case cause was in incorrect 'package name' in OATH client settings:
was: com.blabla.prog
correct one: bla.bla.com.prog
try to ignore the API connection by doing this:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApiIfAvailable(Drive.API)
I've done in this way and everything seems working. I really don't know why, i suppose that the Driver.API creates some problems, and doing in this way you can use the maps,the markers and all that stuff. I know that is not a good answer because i don't provide you a correct explanation, but anyway, it can help.
This type of error may occur in following situations:
If you have used release key SHA1 signing-certificate fingerprint while creating Oauth 2.0 client ID and running your application without signing it with release key (i.e. running with debug key). This is also true for debug key.
If you have used different package name while creating Oauth 2.0 client ID
Another thing that can go wrong is that you create credentials for "API Key" instead of "OAuth 2.0 client ID".
Yeah silly I know.. guide says "Client ID" so I guess I went by the length of the string :)

Categories

Resources