【问题标题】:How to detect dismissal of the google "choose account" dialog如何检测解雇谷歌“选择帐户”对话框
【发布时间】:2016-09-12 06:24:13
【问题描述】:

我正在我的 Android 应用中集成 Google SSO。 我想知道何时提示用户选择帐户对话框并决定单击背景,因此该对话框被关闭。

选择帐户对话框由以下人员触发:

    @Override
    public void onConnected(Bundle connectionHint) {
        Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
        Activity activity = MyActivity.getActivity();
        activity.startActivityForResult(signInIntent, RC_GET_TOKEN);    
    }

我正在使用 onActivityResult,但我不知道如何区分登录失败和对话框关闭。

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RC_GET_TOKEN) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        if (result.isSuccess()) {
            //do something
        } else {
            // This is where I get when sign in fails, or when user dismisses the dialog
        }
    }
}

非常感谢您的帮助, 谢谢, 乔拉。

【问题讨论】:

    标签: android google-sso


    【解决方案1】:

    对话框启动代码:

     Intent intent = AccountPicker.newChooseAccountIntent(null, null,
                    new String[] {"com.google", "com.google.android.legacyimap"},
                    false, null, null, null, null);
            startActivityForResult(intent, RC_GET_TOKEN);
    

    关于活动结果:

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == RC_GET_TOKEN) {
            //result code contains 0 if dialog dismissed by clicking on background or pressing Cancel button 
            // or  -1 if OK button is clicked.Tested on Samsung galaxy S5 Android 6.0
    
            boolean dialogIsDismissed;
            if(resultCode ==0) dialogIsDismissed = true;
            if(resultCode ==-1) dialogIsDismissed = false;
    
            GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
            if (result.isSuccess()) {
                //do something
            } else {
                // This is where I get when sign in fails, or when user dismisses the dialog
            }
        }
    }
    

    这是你需要的还是我误会了?

    【讨论】:

    • 选择帐户对话框由 getSignInIntent 自动弹出,并且在这两种情况下 resultCode 都是 0。解雇与否..
    猜你喜欢
    • 1970-01-01
    • 2013-01-01
    • 2013-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-09
    • 2017-07-27
    • 2014-12-01
    相关资源
    最近更新 更多