无法转换为com.google.android.gms.common.api.GoogleApiClient $ OnConnectionFailedListener

时间:2017-12-17 18:54:48

标签: android android-signing

我正在尝试在应用中插入Google登录但我有以下错误:

java.lang.RuntimeException:无法启动活动ComponentInfo {com.gf.globalflow / com.gf.globalflow.LoginTienda}:java.lang.ClassCastException: com.gf.globalflow.LoginTienda无法强制转换为com.google.android.gms.common.api.GoogleApiClient $ OnConnectionFailedListener  引起:java.lang.ClassCastException:com.gf.globalflow.LoginTienda无法强制转换为  com.google.android.gms.common.api.GoogleApiClient $ OnConnectionFailedListener,地址为com.gf.globalflow.LoginTienda.onCreate(LoginTienda.java:108)

我知道实现OnConnectionFailedListener方法可以修复此错误,但我这样做并且错误没有修复。

代码:

glogin = (SignInButton) findViewById(R.id.btngoogle);

GoogleSignInOptions gSignInOptions = new 

GoogleSignInOptions.
Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).
requestEmail().
build();

final GoogleApiClient gApiClient = new GoogleApiClient //this is the line of the error
            .Builder(this)
            .enableAutoManage(this, 
            (GoogleApiClient.OnConnectionFailedListener) this)
            .addOnConnectionFailedListener(new 
            GoogleApiClient.OnConnectionFailedListener()
            {
                @Override
                public void onConnectionFailed(@NonNull ConnectionResult 
                connectionResult)
                {
                    Toast.makeText(getApplicationContext(),"La conexión al 
                    cliente api de Google ha fallado",
                    Toast.LENGTH_LONG).show();
                }
            })
            .addApi(Auth.GOOGLE_SIGN_IN_API,gSignInOptions)
            .build();

        glogin.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                if(v.getId() == R.id.btngoogle)
                {
                    gSignIn();
                }
            }
        }
        );

public void gSignIn()
{
    Intent i = Auth.GoogleSignInApi.getSignInIntent(gApiClient);
    startActivityForResult(i,CODIGO_REQ);

}

public void HandleResult(GoogleSignInResult gSignInResult)
{
    if(gSignInResult.isSuccess())
    {
        GoogleSignInAccount gSignInAccount = 
        gSignInResult.getSignInAccount();
        gnombre = gSignInAccount.getDisplayName();
        gapellido = gSignInAccount.getFamilyName();
        gcorreo = gSignInAccount.getEmail();
        gfoto_url = gSignInAccount.getPhotoUrl().toString();
        Glide.with(this).load(gfoto_url).into(gfoto);
    }
    else
    {
        Toast.makeText(getApplicationContext(),"Usuario o contraseña 
        incorrecta",Toast.LENGTH_LONG).show();
    }
 }

出了什么问题?

谢谢

0 个答案:

没有答案