I am trying to implement App invites in my app. Here's the java code that I am using :
Intent intent = new AppInviteInvitation.IntentBuilder(getString(R.string.invitation_title))
.build();
startActivityForResult(intent, Constants.REQUEST_CODE_INVITE);
But, as soon as I am clicking on the button which executes this code, a dialog pops up saying 'Unfortunately, Google Play Services has stopped'.
I have tried disabling, uninstalling and installing google play services again, and even restarting the phone, but no use.
No Exception is shown in android studio logs, so I am not able to figure out the problem is.
Please help.
There are a few issues here, and I'd also you to validate values.
getString requires resources. Assuming you are calling this from in an activity, you need to call
getResources().getString(R.....). You are likely getting null
returned which would result in an exception.
Although there is only 1 required parameter, you should fill out a few more to make sure you have a reasonable invitation, specifically setMessage(). Also, you can use setAccount() if you know the account, otherwise it will prompt.
I would also validate the input values. For example, log the string value you get for R.string.invitation_title to make sure you have set this correctly before you call the builder.
I was making a silly mistake which was leading to the error.
I was not initializing the GoogleApiClient before sending out the intent. Don't know how I missed it.
Here's the code that I was missing :
GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(AppInvite.API)
.enableAutoManage(this, this)
.build();
Hope it helps future visitors to this page.
Related
Background:
I need to authenticate on my server back-end so I know the client is genuine. In my Android game I connect to Games.API via GoogleApiClient.
I only want to have to sign in once, which I want to do via Games.API, as this gives me many advantages (Google Play Games leaderboards, achievements, etc.)
I have been able to get an authorisation token using GoogleAuthUtil.getToken(...) which I can do after I sign into Games.API, which seems to give me a token. Good so far.
But Google says this is not safe and says I should migrate to ID token flow instead. But, as I understand it this approach would require me to use
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
which means instigating an additional sign in to that for Games.API. Furthermore, it is not possible to addApi both Games.API and Auth.GOOGLE_SIGN_IN_API to the same GoogleApiClient !
Ok, so upgrade to the latest google-play-services (at least r29), using which I can use Games.API with Games.getGamesServerAuthCode(...) to obtain an auth token for my server. But this has two problems: (1) it requires Android 6.0 or above which blocks out 80% of the market, and (2) it's deprecated !
Question:
Should I use GoogleAuthUtil.getToken(...) or not, and if not what are my options given that I only want to sign in using Games.API ?
By sign in I mean present the user with log in visuals. I don't mind signing into something else so long as the user does not have to interact with the sign in...
Note:
I originally asked this question when I first started out. The current question hopefully clarifies the situation.
Firstly, I should not use GoogleAuthUtil.getToken(...). It's deprecated; end of.
To achieve what I want I found the following works perfectly... whether it's the best way I have no idea.
First, sign in using Auth.GOOGLE_SIGN_IN:
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(
GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestIdToken("YOUR-SERVER-CLIENT-ID")
.build();
mGoogleApiClientForSignIn = new GoogleApiClient.Builder(mActivity, this, this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
mGoogleApiClientForSignIn.connect();
On success this will eventually call onConnected(...) from where you can negotiate a second sign in to Games.API. This has to be performed separately on a new GoogleApiClient because you can't mix Games.API and Auth.GOOGLE_SIGN_IN:
mGoogleApiClientForGames = new GoogleApiClient.Builder(mActivity, this, this)
.addApi(Games.API).addScope(Games.SCOPE_GAMES)
.addApi(Drive.API).addScope(Drive.SCOPE_APPFOLDER)
.build();
mGoogleApiClientForGames.connect();
As per the new Play Games Permissions update for 2016, the GoogleSignIn only appears once per game (even between devices !), after which the user is not presented with any visual log in screens for GoogleSignIn. The only visual login will be the Saved Games snapshot selection screen.
This works with Android 2.3 (use google-play-services r28) and without deprecation warnings. Huzzah !
I have installed the fabric,integrated jar files and API key.I am always on "https://www.fabric.io/onboard" instead of " https://fabric.io/dashboard".Unable to see the crash report.I have used correct email Id.
Please help,Thanks in advance.
you can see the app here
https://fabric.io/home
and please wait some time to get updated .also double check in your app below line is enabled or not
Fabric.with(this, new Crashlytics());
also check these from the documentation
If you're getting started with Crashlytics for Android,
Make sure our SDK line is after all other 3rd-party SDKs Force a crash
and then relaunch the app. If you're using our
Crashlytics.getInstance().crash() method for testing purposes, make
sure it's not in the onCreate method of your launch Activity
I'm trying to use the Google Drive REST API - using the exact sample code found at Android REST Quickstart. However I cannot set an account name for the Google Account Credential object in the the onActivityResult method.
I don't get it as I've triple checked that mCredential.setSelectedAccountName(accountName); is definitely being passed an email string for the account name, but when I try and use mCredential.getSelectedAccountName() it always returns null immediately after it has supposedly been set. This means that the account picker is constantly being called but never sets an account name.
Someone please help as this is driving me crazy!
If You are running your application on android version 6.+ then make sure that your app has all the required permission allowed. You can check this by going Setting->apps->your_app->apps permission.
I am trying to enable Saved Game in my Android game. However, I find that if I call
builder.addApi(Drive.API);
builder.addScope(Drive.SCOPE_APPFOLDER);
the "Select Account" dialog doesn't even shown at all, and I cannot therefore sign in.
Uncommenting both lines and everything works fine (sign in, leaderboard, achievement) except Save Game. Trying to get a Snapshot gives me the following error
01-11 23:30:14.549 18072-18488/? E/Evaderīš Must include Drive.SCOPE_APPFOLDER to use snapshots!
java.lang.IllegalStateException: Must include Drive.SCOPE_APPFOLDER to use snapshots!
Is this deprecated? This is the method recommended on https://developers.google.com/games/services/android/savedgames
I am working with LibGDX and the BaseGameUtils if that's relevant
If the code you included in your question is accurate, the problem is in how you are calling the Builder class.
The client is constructed using a builder pattern, so you need to update the return value of the previous call when creating the builder instance, such as: (notice there is only one semi-colon).
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Games.API).addScope(Games.SCOPE_GAMES)
.addApi(Drive.API).addScope(Drive.SCOPE_APPFOLDER)
.build();
The problem wasn't with the code whatsoever. It was the phone(test device).
I tested on another device and it worked flawlessly.
I updated uninstalled Google Play Store and Google Play Services updates, and re-installed them, and everything worked.
TLDR - Test on multiple devices. I'm not exactly sure why that happened on my device for my game only, but after performing the above, everything works.
Thanks Clayton Wilkinson
When I click on the Google+ login button I get a toast naming an "internal error". No error is logged. Also I'm using at the same time the google map api's with no problem, so I think the key value is correct. So what's the problem?
The PlusClient initialization:
mPlusClient = new PlusClient.Builder(this, this, this)
.setActions("http://schemas.google.com/AddActivity", "http://schemas.google.com/BuyActivity")
.setScopes("PLUS_LOGIN") // Space separated list of scopes
.build();
I have removed from the Google API Console the OAuth 2.0 Client corresponding to my app... And now it's working. I have no clue about the reason of this behaviour, because I have strictly followed the tutorial.
The scope you are using is wrong, try instead using:
https://www.googleapis.com/auth/plus.login
It looks like the documentation references the same scope as your example, which I believe instead should be a library constant (com.google.android.gms.common.Scopes.PLUS_LOGIN) that will ultimately resolve to the previously referenced scope.
I've removed key created with new api interface and created client id with old edit api interface. and now it works.
you must fill the "Consent Screen" under APIs ad Auths , nothing else works if you do not fill the content in "Consent Screen".