android - Google plus 登录在 AuthLogin 上显示虚拟白色 AlertDialog

标签 android google-signin

我正在尝试从我的应用程序中使用 Google+ 登录。一切正常,但我遇到了一个白点,就像一个空的警报对话框。

screenshot

最佳答案

请引用以下链接,了解 Google 与我们应用程序的集成。 https://developers.google.com/identity/sign-in/android/start-integrating

需要记住的几个步骤如下: 1) 单击 https://developers.google.com/identity/sign-in/android/start-integrating 中的生成配置按钮生成 google-service.json 文件

2) 复制google-service.json文件到应用的app文件夹

3) 仔细按照开发者链接的步骤

有代码截图引用:

   @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                    .requestEmail()
                    .build();
            // Build a GoogleApiClient with access to the Google Sign-In API and the
    // options specified by gso.
            mGoogleApiClient = new GoogleApiClient.Builder(this)
                    .enableAutoManage(this, this)
                    .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                    .build();
    } 
    /**
         *
         * Google plus
         *
         */
        private void signIn(){
            Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
            startActivityForResult(signInIntent, RC_SIGN_IN);
        }
        // [END signIn]
        // [START signOut]
        private void signOut() {
            Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
                    new ResultCallback<Status>() {
                        @Override
                        public void onResult(Status status) {
                            // [START_EXCLUDE]
                            //  updateUI(false);
                            // [END_EXCLUDE]
                        }
                    });
        }
        private void handleSignInResult(GoogleSignInResult result) {
            Log.d("LOGIN", "handleSignInResult:" + result.isSuccess());
            if (result.isSuccess()) {
                // Signed in successfully, show authenticated UI.
                Constant.socail_data = "Google+";
                GoogleSignInAccount acct = result.getSignInAccount();
                String personName = acct.getDisplayName();
                firstName = acct.getDisplayName().split(" ")[0];
                if(acct.getDisplayName().split(" ")[1]!=  null){
                    lastName = acct.getDisplayName().split(" ")[1];
                }
                googleEmail = acct.getEmail();
                String personId = acct.getId();
                Uri personPhoto = acct.getPhotoUrl();
                Toast.makeText(LoginActivity.this, personName, 30).show();
                System.out.println(personName + ">>>" +googleEmail  + ">>" + personId + ">>>" + personPhoto);

            } else {
            }
        }
        // [START revokeAccess]
        private void revokeAccess() {
            Auth.GoogleSignInApi.revokeAccess(mGoogleApiClient).setResultCallback(
                    new ResultCallback<Status>() {
                        @Override
                        public void onResult(Status status) {
                            // [START_EXCLUDE]
                            System.out.println("LOGIN"+status.toString());
                            // [END_EXCLUDE]
                        }
                    });
        }
     @Override
        public void onStart() {
            super.onStart();
    OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
            if (opr.isDone()) {
                // If the user's cached credentials are valid, the OptionalPendingResult will be "done"
                // and the GoogleSignInResult will be available instantly.
                Log.d("LOGIN", "Got cached sign-in");
                GoogleSignInResult result = opr.get();
                handleSignInResult(result);
            } else {
                // If the user has not previously signed in on this device or the sign-in has expired,
                // this asynchronous branch will attempt to sign in the user silently.  Cross-device
                // single sign-on will occur in this branch.
                showProgressDialog();
                opr.setResultCallback(new ResultCallback<GoogleSignInResult>() {
                    @Override
                    public void onResult(GoogleSignInResult googleSignInResult) {
                        hideProgressDialog();
                        handleSignInResult(googleSignInResult);
                    }
                });
            }
        }

有关演示,请参阅 https://github.com/googlesamples/google-services

关于android - Google plus 登录在 AuthLogin 上显示虚拟白色 AlertDialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35099587/

相关文章:

java - 更新回收者 View 数据

android - Android ListView 的 transcriptMode 是什么?

android - 在 App Billing v3 IllegalArgumentException 中使用 IabHelper

android - java.lang.IllegalAccessError : Class ref in pre-verified class resolved to unexpected implementation after adding AppCompat to stable application 错误

javascript - 使用 Google oAuth 2.0 时刷新新用户登录页面

javascript - 我想在点击 Google Plus 按钮时调用 Google Plus 回调函数

android - 在 NPObject 上调用方法时出错!在安卓 2.2

android - Firebase Auth Ui Google 登录 "Developer Error"

android - 谷歌登录,当用户被要求再次登录帐户时如何正确处理错误情况

javascript - 使用 javascript 的 Google 登录(网站)