Rare NullPointerException in GoogleApiClient using Firebase

白昼怎懂夜的黑 提交于 2019-12-03 02:12:14

Hello You can try this code this is a working code in my project first initialize google api client in on create

public void initGPlus() {
    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();
}

and on the button click call another function

 Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
    startActivityForResult(signInIntent, RC_SIGN_IN);

In On Activity result just got your response and handle that result in a function

if (requestCode == RC_SIGN_IN) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        handleSignInResult(result);
    }

implement this interface in your activity

 implements GoogleApiClient.OnConnectionFailedListener

While checking for Google Play services would be good, I think this may be due to a device having an old version of Google Play services.but that's not a great error regardless.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!