Hi
hear i am facing a problem to get signout feom the GoogleApiClient, the following is the code i am using currently,
Here is for the Signin
protected override void OnCreate(Bundle savedInstanceState)
{
try
{
base.OnCreate(savedInstanceState);
//Common.packageName = ApplicationContext.PackageName;
SetContentView(Resource.Layout.activity_gmail);
Common.clearCatchecontext = this;//ApplicationContext;
FindViewById(Resource.Id.sign_in_button).Click += GoogleSignInButton_Click;
var gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn)
.RequestIdToken("5423.apps.googleusercontent.com")
.RequestEmail()
.Build();
Common.mGoogleApiClient = new GoogleApiClient.Builder(this)
.EnableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.AddApi(Android.Gms.Auth.Api.Auth.GOOGLE_SIGN_IN_API, gso)
.Build();
Common.mGoogleApiClient.Connect();
Common.mAuth = FirebaseAuth.Instance;
}
catch (Exception ex)
{
throw new Exception(ex.Message + ex.StackTrace + ex.InnerException);
}
}
once after success signin the application will call the LoadApplication(App) to redirect from pureAndroid Platoform to the crossPlatoform,
then to signOut, form the xamarin forms will call the android method as dependency injection,
Interface class and a method,
public interface ISignOut
{
void SignOuts(string _value);
}
the below is the button click,
private async void TapRecognizserLogOut_Tapped(object sender, EventArgs e)
{
try
{
var result = await DisplayAlert("Alert!", "Do you really want to Logout the application?", "Yes", "No");
if (result)
{
if (Xamarin.Forms.Device.OS == TargetPlatform.Android)
{
DependencyService.Get<ISignOut>().SignOuts("HAI");
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.InnerException + ex.StackTrace + ex.Message);
}
}
in the android implementation is below,
[assembly: Xamarin.Forms.Dependency(typeof(GmailSignInActivity))]
namespace Xaamrin_Mobile.Droid
{
[Activity(Label = "GmailSignInActivity", Theme = "@style/MainTheme")]
class GmailSignInActivity : AppCompatActivity, GoogleApiClient.IOnConnectionFailedListener, GoogleApiClient.IConnectionCallbacks, ISignOut
{
public async void SignOuts(string _value)
{
try
{
if (true)
{
var _res = LoginUser._loginUser;
FirebaseAuth.Instance.SignOut();
if (!Common.mGoogleApiClient.IsConnected)
{
Common.mGoogleApiClient.Connect();
await Auth.GoogleSignInApi.SignOut(Common.mGoogleApiClient);//.GetAwaiter().GetResult();
}
Common.mGoogleApiClient.Disconnect();
Common.mGoogleApiClient.Connect();
var user = FirebaseAuth.Instance.CurrentUser;
}
}
catch (Exception ex)
{
//throw;
}
var intent = new Intent(Forms.Context, typeof(GmailSignInActivity));
Forms.Context.StartActivity(intent);
//return false;
}
}
}
like the above way, we are implemented, but we are not able to get signout from the GoogleAPIClient,