void Reconnect() { if (_client != null) { _client.Reconnect(); } }
public void OnConnectionSuspended(int i) { DebugLog("onConnectionSuspended: " + i); UpdateViewVisibility(NearbyConnectionState.Idle); // Try to re-connect mGoogleApiClient.Reconnect(); }
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { logVerbose(String.Format("onActivityResult - requestCode:{0} resultCode:{1}", requestCode, resultCode)); if (requestCode == REQUEST_CODE_SIGN_IN || requestCode == REQUEST_CODE_GET_GOOGLE_PLAY_SERVICES) { mIntentInProgress = false; //Previous resolution intent no longer in progress. if (resultCode == Result.Ok) { // After resolving a recoverable error, now retry connect(). Note that it's possible // mGoogleApiClient is already connected or connecting due to rotation / Activity // restart while user is walking through the (possibly full screen) resolution // Activities. We should always reconnect() and ignore earlier connection attempts // started before completion of the resolution. (With only one exception, a // connect() attempt started late enough in the resolution flow and it actually // succeeded) if (!mGoogleApiClient.IsConnected) { logVerbose("Previous resolution completed successfully, try connecting again"); mGoogleApiClient.Reconnect(); } } else { mSignInClicked = false; // No longer in the middle of resolving sign-in errors. if (resultCode == Result.Canceled) { mSignInStatus.Text = GetString(Resource.String.signed_out_status); } else { mSignInStatus.Text = GetString(Resource.String.sign_in_error_status); Console.WriteLine("Error during resolving recoverable error."); } } } }
protected override void OnCreate (Bundle savedInstanceState) { base.OnCreate (savedInstanceState); // If you want to understand the life cycle more, you can use below command to turn on // verbose logging for this Activity on your testing device: // adb shell setprop log.tag.SignInActivity VERBOSE mIsLogVerbose = Android.Util.Log.IsLoggable (TAG, Android.Util.LogPriority.Verbose); SetContentView (Resource.Layout.sign_in_activity); restoreState (savedInstanceState); logVerbose("Activity onCreate, creating new GoogleApiClient"); mGoogleApiClient = buildGoogleApiClient (false); mSignInStatus = FindViewById<TextView> (Resource.Id.sign_in_status); mSignInButton = FindViewById<SignInButton> (Resource.Id.sign_in_button); mSignInButton.Click += (sender, e) => { if (!mGoogleApiClient.IsConnecting) { int available = GooglePlayServicesUtil.IsGooglePlayServicesAvailable (this); if (available != ConnectionResult.Success) { ShowDialog (DIALOG_GET_GOOGLE_PLAY_SERVICES); return; } mSignInClicked = true; mSignInStatus.Text = GetString (Resource.String.signing_in_status); resolveSignInError(); } }; mServerAuthCodeDisabledLabel = FindViewById<TextView> (Resource.Id.server_auth_code_disabled); mServerAuthCodeResetButton = FindViewById<View>(Resource.Id.server_auth_code_reset_button); mServerAuthCodeResetButton.Click += (sender, e) => { mServerAuthCodeRequired.Set (true); }; if (!isUsingOfflineAccess()) { mServerAuthCodeDisabledLabel.Visibility = ViewStates.Visible; mServerAuthCodeResetButton.Visibility = ViewStates.Gone; } else { mServerAuthCodeDisabledLabel.Visibility = ViewStates.Gone; mServerAuthCodeResetButton.Visibility = ViewStates.Visible; } mSignOutButton = FindViewById<View> (Resource.Id.sign_out_button); mSignOutButton.Click += (sender, e) => { if (mGoogleApiClient.IsConnected) mGoogleApiClient.ClearDefaultAccountAndReconnect (); }; mRevokeAccessButton = FindViewById(Resource.Id.revoke_access_button); mRevokeAccessButton.Click += (sender, e) => { mServerAuthCodeRequired.Set (true); if (mGoogleApiClient.IsConnected) { PlusClass.AccountApi.RevokeAccessAndDisconnect (mGoogleApiClient).SetResultCallback<Statuses> (result => { if (result.IsSuccess) { mSignInStatus.SetText(Resource.String.revoke_access_status); } else { mSignInStatus.SetText(Resource.String.revoke_access_error_status); } mGoogleApiClient.Reconnect (); }); updateButtons (false /* isSignedIn */); } }; mScopeSelector = FindViewById<ToggleButton> (Resource.Id.scope_selection_toggle); mScopeSelector.CheckedChange += (sender, e) => { mGoogleApiClient.Disconnect (); // Since we changed the configuration, the cached connection result is no longer // valid. mConnectionResult = null; mGoogleApiClient = buildGoogleApiClient (e.IsChecked); mGoogleApiClient.Connect(); }; if (Build.VERSION.SdkInt >= BuildVersionCodes.Honeycomb) { ActionBar.SetDisplayHomeAsUpEnabled (true); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // If you want to understand the life cycle more, you can use below command to turn on // verbose logging for this Activity on your testing device: // adb shell setprop log.tag.SignInActivity VERBOSE mIsLogVerbose = Android.Util.Log.IsLoggable(TAG, Android.Util.LogPriority.Verbose); SetContentView(Resource.Layout.sign_in_activity); restoreState(savedInstanceState); logVerbose("Activity onCreate, creating new GoogleApiClient"); mGoogleApiClient = buildGoogleApiClient(false); mSignInStatus = FindViewById <TextView> (Resource.Id.sign_in_status); mSignInButton = FindViewById <SignInButton> (Resource.Id.sign_in_button); mSignInButton.Click += (sender, e) => { if (!mGoogleApiClient.IsConnecting) { int available = GooglePlayServicesUtil.IsGooglePlayServicesAvailable(this); if (available != ConnectionResult.Success) { ShowDialog(DIALOG_GET_GOOGLE_PLAY_SERVICES); return; } mSignInClicked = true; mSignInStatus.Text = GetString(Resource.String.signing_in_status); resolveSignInError(); } }; mServerAuthCodeDisabledLabel = FindViewById <TextView> (Resource.Id.server_auth_code_disabled); mServerAuthCodeResetButton = FindViewById <View>(Resource.Id.server_auth_code_reset_button); mServerAuthCodeResetButton.Click += (sender, e) => { mServerAuthCodeRequired.Set(true); }; if (!isUsingOfflineAccess()) { mServerAuthCodeDisabledLabel.Visibility = ViewStates.Visible; mServerAuthCodeResetButton.Visibility = ViewStates.Gone; } else { mServerAuthCodeDisabledLabel.Visibility = ViewStates.Gone; mServerAuthCodeResetButton.Visibility = ViewStates.Visible; } mSignOutButton = FindViewById <View> (Resource.Id.sign_out_button); mSignOutButton.Click += (sender, e) => { if (mGoogleApiClient.IsConnected) { mGoogleApiClient.ClearDefaultAccountAndReconnect(); } }; mRevokeAccessButton = FindViewById(Resource.Id.revoke_access_button); mRevokeAccessButton.Click += (sender, e) => { mServerAuthCodeRequired.Set(true); if (mGoogleApiClient.IsConnected) { PlusClass.AccountApi.RevokeAccessAndDisconnect(mGoogleApiClient).SetResultCallback <Statuses> (result => { if (result.IsSuccess) { mSignInStatus.SetText(Resource.String.revoke_access_status); } else { mSignInStatus.SetText(Resource.String.revoke_access_error_status); } mGoogleApiClient.Reconnect(); }); updateButtons(false /* isSignedIn */); } }; mScopeSelector = FindViewById <ToggleButton> (Resource.Id.scope_selection_toggle); mScopeSelector.CheckedChange += (sender, e) => { mGoogleApiClient.Disconnect(); // Since we changed the configuration, the cached connection result is no longer // valid. mConnectionResult = null; mGoogleApiClient = buildGoogleApiClient(e.IsChecked); mGoogleApiClient.Connect(); }; if (Build.VERSION.SdkInt >= BuildVersionCodes.Honeycomb) { ActionBar.SetDisplayHomeAsUpEnabled(true); } }