【问题标题】:Signing out google account from fragement(bottomnavigation)从片段中注销谷歌帐户(底部导航)
【发布时间】:2020-08-23 20:06:13
【问题描述】:

由于退出按钮在片段上,我不能将“this”用作 Activity,我可以用什么替换?

    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
        .requestIdToken(getString(R.string.default_web_client_id))
        .requestEmail()
        .build();
GoogleSignInClient mGoogleSignInClient = GoogleSignIn.getClient(this,gso);

错误信息

error: no suitable method found for getClient(DashboardFragment,GoogleSignInOptions)
GoogleSignInClient mGoogleSignInClient = GoogleSignIn.getClient(this,gso);
                                                     ^
method GoogleSignIn.getClient(Context,GoogleSignInOptions) is not applicable
  (argument mismatch; DashboardFragment cannot be converted to Context)
method GoogleSignIn.getClient(Activity,GoogleSignInOptions) is not applicable
  (argument mismatch; DashboardFragment cannot be converted to Activity)

【问题讨论】:

    标签: android android-studio google-authentication


    【解决方案1】:

    GoogleSignIn.getClient(Context,GoogleSignInOptions) 需要上下文而不是片段。

    这样使用:

    GoogleSignInClient mGoogleSignInClient = GoogleSignIn.getClient(getContext(),gso);
    

    请注意,如果片段未附加,getContext() 可能会返回 null

    【讨论】:

      猜你喜欢
      • 2016-11-29
      • 2022-06-16
      • 2011-05-11
      • 2021-12-03
      • 2020-11-08
      • 1970-01-01
      • 2020-06-23
      • 2022-11-04
      • 1970-01-01
      相关资源
      最近更新 更多