Google登录无法正常运行android吗? [英] Google sign in not working android?

查看:70
本文介绍了Google登录无法正常运行android吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我的项目遇到的一个问题是通过google登录无法始终如一地工作.即,它适用于我的朋友,而不适用于我的计算机,即使它昨天对我有效,但我擦了手机(电话已损坏).我们的登录代码是Google登录的标准,问题是我认为结果总是返回false.代码:

So an issue my project has encountered is that the sign in through google does not work consistently. Ie, it works for my friend and not me from my computer, even though it worked for me yesterday before wiping my phone (phone got corrupted). Our login code is the standard for google sign in, and the problem is that the result keeps returning false I think. the code:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.welcome_screen);
        findViewById(R.id.sign_in_button).setOnClickListener(this);

        GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestEmail()
                .build();

        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
                .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                .build();

        SignInButton signInButton = (SignInButton) findViewById(R.id.sign_in_button);
        signInButton.setSize(SignInButton.SIZE_STANDARD);
        signInButton.setScopes(gso.getScopeArray());

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.sign_in_button:
                signIn();
                break;
        }
    }   

private void signIn() {
        Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
        startActivityForResult(signInIntent, RC_SIGN_IN);
    }

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
        if (requestCode == RC_SIGN_IN) {
            GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
            handleSignInResult(result);
        }
    }

    private void handleSignInResult(GoogleSignInResult result) {
        if (result.isSuccess()) {
            // Signed in successfully, show authenticated UI.
            GoogleSignInAccount acct = result.getSignInAccount();

//            mStatusTextView.setText(getString(R.string.signed_in_fmt, acct.getDisplayName()));
            updateUI(acct);
        } else {
            // Signed out, show unauthenticated UI.
            noUpdateUI();
        }
    }

    private void updateUI(GoogleSignInAccount acct) {
        Intent intent = new Intent(getApplicationContext(), HomeScreen.class);

        Bundle bundle = new Bundle();
        bundle.putSerializable("NEW_USER", new ClientUser(acct));
        intent.putExtras(bundle);

        startActivity(intent);
    }


For some reason, the result is false:

    private void noUpdateUI() {
        System.out.println("**** Try again****");
//        mStatusTextView.setText(R.string.signed_out);
        findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
    }

我认为我已经正确设置了我的应用程序的凭据,因为它在擦除手机之前可以在桌面上使用.值得注意的是,我的朋友在笔记本电脑上工作时遇到了同样的问题,但在台式机上工作时却没有遇到问题.不知道发生了什么事;有什么建议吗?

I think I have set up my app's credentials correctly, as it worked previously from my desktop before I wiped my phone. Of note, my friend had the same issue working from his laptop, but does not have the issue working from his desktop. Not sure what's up; any suggestions?

sys.out中的日志:

The log from sys.out:

12-16 18:48:43.282 27375-27375/oose2017.place2b D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
12-16 18:48:43.412 27375-27375/oose2017.place2b I/Timeline: Timeline: Activity_launch_request id:oose2017.place2b time:3231784
12-16 18:48:43.452 27375-27375/oose2017.place2b D/Activity: performCreate Call Injection manager
12-16 18:48:43.462 27375-27375/oose2017.place2b I/InjectionManager: dispatchOnViewCreated > Target : com.google.android.gms.auth.api.signin.internal.SignInHubActivity isFragment :false
12-16 18:48:43.462 27375-27375/oose2017.place2b D/PhoneWindow: *FMB* installDecor mIsFloating : false
12-16 18:48:43.462 27375-27375/oose2017.place2b D/PhoneWindow: *FMB* installDecor flags : 8454400
12-16 18:48:43.462 27375-27375/oose2017.place2b D/SecWifiDisplayUtil: Metadata value : SecSettings2
12-16 18:48:43.472 27375-27375/oose2017.place2b D/PhoneWindow: *FMB* isFloatingMenuEnabled mFloatingMenuBtn : null
12-16 18:48:43.472 27375-27375/oose2017.place2b D/PhoneWindow: *FMB* isFloatingMenuEnabled return false
12-16 18:48:43.482 27375-27375/oose2017.place2b D/SRIB_DCS: log_dcs ThreadedRenderer::initialize entered! 
12-16 18:48:43.492 27375-27584/oose2017.place2b D/mali_winsys: new_window_surface returns 0x3000,  [1440x2560]-format:1
12-16 18:48:43.542 27375-27375/oose2017.place2b I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@174719e3 time:3231916
12-16 18:48:43.962 27375-27375/oose2017.place2b V/ActivityThread: updateVisibility : ActivityRecord{1458bd29 token=android.os.BinderProxy@e9978a8 {oose2017.place2b/oose2017.place2b.interfaces.Welcome.WelcomeScreen}} show : true
12-16 18:48:43.962 27375-27375/oose2017.place2b V/ActivityThread: updateVisibility : ActivityRecord{d3e4299 token=android.os.BinderProxy@174719e3 {oose2017.place2b/com.google.android.gms.auth.api.signin.internal.SignInHubActivity}} show : true
12-16 18:48:48.102 27375-27375/oose2017.place2b I/System.out: ***** Try again!*****
12-16 18:48:48.132 27375-27375/oose2017.place2b I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@e9978a8 time:3236507

推荐答案

我遇到了同样的问题. 我通过执行以下操作解决了该问题:

I had the same problem. I solved it by doing the following:

  1. 我去了defaultConfig内的build.gradle(app)并将applicationId更改为我的程序包名称(我不知道为什么它最初并不相同). 我从compile 'com.google.android.gms:play-services-auth:8.3.0'切换到compile 'com.google.android.gms:play-services-auth:8.4.0' 确保apply plugin: 'com.google.gms.google-services'在build.gradle(app)的底部,即依赖项之后

  1. I went to my build.gradle(app), inside defaultConfig and changed the applicationId to my package name (I dont know why it wasnt the same initially). I switched from compile 'com.google.android.gms:play-services-auth:8.3.0' to compile 'com.google.android.gms:play-services-auth:8.4.0' Make sure apply plugin: 'com.google.gms.google-services' is at the bottom of your build.gradle(app) i.e after the dependencies

我生成了一个新的SHA-1密钥.要生成SHA-1密钥,请将其粘贴到您的终端中:keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android 然后转到您的凭据页面,然后选择您的项目.

I generated a new SHA-1 key. To generate SHA-1 key paste this in your terminal: keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android then go to your credentials page and select your project.

在OAuth 2.0客户端下,单击您的android客户端密钥.按照指示粘贴您生成的SHA-1密钥和程序包名称.点击保存.

under OAuth 2.0 client, click your android client key. paste the SHA-1 key you generated and your package name as directed. click save.

  1. 下载一个新的google-services.json文件并将其粘贴到您的app/目录中.

然后尝试再次登录.希望它应该工作. 有关更多信息,请参见此帖子

Then try signing in again. Hopefully it should work. For more info, see this post and this as well. It helped me solve mine

这篇关于Google登录无法正常运行android吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆