I implemented a google account sign in button for my app, when I open the app (Android 6.0.1) and enter the sign in page, it shows a dialog saying This app won't run unless you update google play services
This is my code:
compile 'com.google.android.gms:play-services:9.2.1'
compile 'com.google.android.gms:play-services-auth:9.2.1'
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(getActivity().getApplicationContext())
.addApi(Auth.GOOGLE_SIGN_IN_API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mGoogleApiClient.connect();
}
I checked the google play services on my android device is 8.1.86
Is that because 8.1<9.2?
How to avoid this message for my users who has outdated google play services app?
In order to check Google Play Services you can use int isGooglePlayServicesAvailable (Context) method:
GoogleApiAvailability.getInstance()
.isGooglePlayServicesAvailable(context);
If the resultCode = SUCCESS then everything is fine. Otherwise, you decide what to do, if SERVICE_VERSION_UPDATE_REQUIRED you could ask if the user wants to update or you might have other login options.
If you what to show the original dialog call boolean showErrorDialogFragment (Activity activity, int errorCode, int requestCode).
Related
I currently have 4 accounts connected to the Google Drive app on my phone.
I am trying to play a .mp4 file from Google Drive using the following:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(file.getFile().getWebContentLink())));
When I select the Google Drive app to play the file, I am presented with a list of the 4 currently connected accounts.
I already know which account the file is from. Is there any way of passing this account to the the startActivity, maybe as part of the intent?
Try below code it may work and let me know it worked for you or not.:)
#Override
protected void onResume() {
super.onResume();
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.setAccountName("yourmaild#gmail.com")
.addScope(Drive.SCOPE_FILE)
.addScope(Drive.SCOPE_APPFOLDER) // required for App Folder sample
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
mGoogleApiClient.connect();
}
I try to implement Game Play Service Achievement in my game, but when achievement is unlocked, it does not pops up (show that achievement is unlocked) but when I open list of all achievements it shows that is unlocked. So my problem is, how to pops up achievement when it's unlocked ?
MainActivity.class
public static GoogleApiClient mGoogleApiClient;
private void callGooglePlay(){
mGoogleApiClient = new GoogleApiClient.Builder(getApplicationContext())
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Games.API).addScope(Games.SCOPE_GAMES)
.build();
}
PlayActivity.class
Games.Achievements.unlock(MainMenu.mGoogleApiClient, getResources().getString(R.string.e));
You need to call the getAchievementsIntent() to create the default achievements UI, and then call the startActivityForResult
startActivityForResult(Games.Achievements.getAchievementsIntent(mGoogleApiClient),REQUEST_ACHIEVEMENTS);
More information about displaying achievements can be found on the documentation.
If you need a notification that's specific to the achievement being unlocked, you can try to use [setViewForPopups](https://developers.google.com/android/reference/com/google/android/gms/games/Games.html#setViewForPopups(com.google.android.gms.common.api.GoogleApiClient, android.view.View)) as suggested in this question.
I'm following the sample code given by Google to integrate Google plus with android.
https://github.com/googlesamples/google-services/blob/master/android/signin/app/src/main/java/com/google/samples/quickstart/signin/SignInActivity.java
That code sample worked perfectly fine until I added some changes as follows.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestScopes(new Scope(Scopes.PLUS_LOGIN))
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
signinGoogleBtn = (SignInButton) findViewById(R.id.signingoogleBtn);
signinGoogleBtn.setSize(SignInButton.SIZE_STANDARD);
signinGoogleBtn.setScopes(gso.getScopeArray());
I added Google+ scopes to GoogleSignInOptions in order to customize the signin button. Then GoogleSignInResult and handleSignInResult always returns false.
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleSignInResult(result);
Could anyone please help me to fix this issue?
Hey i was having same problem, i think in your case either you have not put your google-services.json file inside your app folder or you are not running your signed apk file if this the case first sign your apk and then paste this apk file in your mobile and from their open it, i mean don't run your app from android studio because what it does is it does not run signed apk file on mobile device. Hope this works :)
In Play Services 6.1.71 I was using:
mPlusClient = new PlusClient.Builder(this,this,this).setActions("http://schemas.google.com/AddActivity", "http://schemas.google.com/BuyActivity").setScopes(Scopes.PLUS_LOGIN, Scopes.PROFILE).build();
But in Google Play Services 6.5.87, Google suggest to change PlusClient to GoogleApiClient.Builder instead. But I'm not able to get user info as before:
mPlusClient.getAccountName()
or
mPlusClient.getCurrentPerson()
How can I retrieve the user info? I think Google documentation is out of date.
Hope you can help me. Thank you.
Use GoogleApiClient, not PlusClient. Sample:
mGoogleApiClient = new GoogleApiClient.Builder(mContext)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
To getAccountName() use Plus.AccountApi.getAccountName(mGoogleApiClient)
To getCurrentPerson() use Plus.PeopleApi.getCurrentPerson(mGoogleApiClient)
Very nice example how to implement login with GoogleApiClient ...
Since it is whole tutorial I do not copy it here.
I am integrating google plus into my app and it works fine with the google_play_service library.But since this library doesn't work in amazon devices my app always crash when I share something from the Amazon devices.So it is only possible to avoid sharing in google plus when using Amazon devices or is there a workaround.
Thanks in advance.
Whenever you use the Google Play Services lib, it is important to check whether the device supports the use of Google Play Services. This is done as follows:
private final static int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
...
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mDisplay = (TextView) findViewById(R.id.display);
context = getApplicationContext();
// Check device for Play Services APK.
if (checkPlayServices()) {
// If this check succeeds, proceed with normal processing.
// Otherwise, prompt user to get valid Play Services APK.
...
}
}
// You need to do the Play Services APK check here too.
#Override
protected void onResume() {
super.onResume();
checkPlayServices();
}
/**
* Check the device to make sure it has the Google Play Services APK. If
* it doesn't, display a dialog that allows users to download the APK from
* the Google Play Store or enable it in the device's system settings.
*/
private boolean checkPlayServices() {
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
GooglePlayServicesUtil.getErrorDialog(resultCode, this,
PLAY_SERVICES_RESOLUTION_REQUEST).show();
} else {
Log.i(TAG, "This device is not supported.");
finish();
}
return false;
}
return true;
}
The above code is usually added to your app's starting activity, and will prevent your application from crashing (throwing an exception) if that device does not support the use of Google Play Services (which is the case with Amazon's Android-based devices). So the answer to your second question, whether we can get access to Google Plus on Amazon devices, is NO.
References:
1. Ensure Devices Have the Google Play services APK.
2. Check for Google Play Services APK.
Yey! soon we cant even use Google Analytics on Amazon android devices! we're already limited in Google Drive support, Chrome cast, Locations API. Developing for "Android" and not only"Google" is becoming harder and harder. Amazon, Google and ebay everyone has its own api for its services.
OR try this.
http://androidcowboy.com/2013/10/add-google-account-kindle-fire-hdx/