Я пытаюсь создать знак входа в Google на странице входа, но застрял с ошибкой.Весь код приведен ниже.
"Неверный 1-й тип аргумента: Найдено 'com.example.sudhakarvijayasarathy.testapp.WelcomeActivity', требуется 'android.support.v4.app.FragmentActivity '--- (enableAutoManage android.support.v4.app.FragmentActivity, OnConnectionFailed Listener) в построителе нельзя применить к (com.example.sudhakarvijayasarathy.testapp.WelcomeActivity, OnConnectionFailed Listener) "1006 **
package com.example.sudhakarvijayasarathy.testapp;
import android.app.Activity;
import android.app.NativeActivity;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentController;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignIn;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.auth.api.signin.GoogleSignInResult;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.SignInButton;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthCredential;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.GoogleAuthProvider;
public class WelcomeActivity extends Activity {
//TextView name;
//Button mWelcomeButton;
SignInButton button;
FirebaseAuth mAuth;
GoogleApiClient mGoogleApiClient;
private static int RC_SIGN_IN = 2;
FirebaseAuth.AuthStateListener mAuthListener;
enter code here
@Override
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener( mAuthListener );
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
requestWindowFeature( Window.FEATURE_NO_TITLE );
setContentView( R.layout.activity_welcome );
button = (SignInButton) findViewById( R.id.googlebtn );
mAuth = FirebaseAuth.getInstance();
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
if (firebaseAuth.getCurrentUser() != null) {
startActivity( new Intent( WelcomeActivity.this, MainActivity.class ) );
}
}
};
mGoogleApiClient = new GoogleApiClient.Builder( this )
.enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
Toast.makeText( WelcomeActivity.this, "Not correct", Toast.LENGTH_SHORT ).show();
}
} )
.addApi( Auth.GOOGLE_SIGN_IN_API, gso )
.build();
//GoogleSignIn.getClient(this, gso);
}
GoogleSignInOptions gso = new GoogleSignInOptions.Builder( GoogleSignInOptions.DEFAULT_SIGN_IN )
.requestIdToken( getString( R.string.default_web_client_id ) )
.requestEmail()
.build();
//name = (TextView) findViewById( R.id.name );
//name.setOnClickListener( new View.OnClickListener() {
/*mWelcomeButton = findViewById(R.id.WelcomeButton);
mWelcomeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent( WelcomeActivity.this, MainActivity.class) ;
startActivity(i);
}*/
private void signIn() {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent( mGoogleApiClient );
startActivityForResult(signInIntent, RC_SIGN_IN);
}
@Override
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 );
if (result.isSuccess()){
// Google Sign In was successful, authenticate with Firebase
GoogleSignInAccount account = result.getSignInAccount();
firebaseAuthWithGoogle(account);
} else {
Toast.makeText( WelcomeActivity.this,"Auth Not correct",Toast.LENGTH_SHORT).show();
// Google Sign In failed, update UI appropriately
// ...
}
}
}
private void firebaseAuthWithGoogle(GoogleSignInAccount account) {
AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
Log.d("TAG", "signInWithCredential:success");
FirebaseUser user = mAuth.getCurrentUser();
//updateUI(user);
} else {
// If sign in fails, display a message to the user.
Log.w("TAG", "signInWithCredential:failure", task.getException());
Toast.makeText( WelcomeActivity.this,"Auth Failed",Toast.LENGTH_SHORT).show();
//Snackbar.make(findViewById(R.id.main_layout), "Authentication Failed.", Snackbar.LENGTH_SHORT).show();
//updateUI(null);
}
// ...
}
});
}
}