Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
登录活动未指向其他android活动_Android_Firebase Authentication_Google Signin - Fatal编程技术网

登录活动未指向其他android活动

登录活动未指向其他android活动,android,firebase-authentication,google-signin,Android,Firebase Authentication,Google Signin,我正在尝试实现谷歌登录,并为此遵循firebase文档 当我使用android studio在我的设备上测试我的应用程序时,我可以成功登录,甚至可以直接进入其他活动。 但在生成apk后,我将其安装到各种设备上,包括我的测试设备,但我无法指导其他活动 public class GoogleSignIn extends AppCompatActivity { private SignInButton googleSignIn; private static final int RC_SIGN_IN

我正在尝试实现谷歌登录,并为此遵循firebase文档

当我使用android studio在我的设备上测试我的应用程序时,我可以成功登录,甚至可以直接进入其他活动。 但在生成apk后,我将其安装到各种设备上,包括我的测试设备,但我无法指导其他活动

public class GoogleSignIn extends AppCompatActivity {

private SignInButton googleSignIn;
private static final int RC_SIGN_IN =1032;
private GoogleApiClient mGoogleApiClient;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
private final static String TAG = "GOOGLESIGNIN";


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.google_sign_in);
    mAuth = FirebaseAuth.getInstance();
    mAuthListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {

            if (firebaseAuth.getCurrentUser() != null){
                startActivity( new Intent(GoogleSignIn.this, MainActivity.class));
            }

        }
    };

    googleSignIn = (SignInButton) findViewById(R.id.sign_in_button);

    // Configure Google Sign In
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(R.string.default_web_client_id))
            .requestEmail()
            .build();

    mGoogleApiClient = new GoogleApiClient.Builder(getApplicationContext())
            .enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener() {
                @Override
                public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {

                }
            })
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();

    googleSignIn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            signIn();
        }
    });


}

@Override
protected void onStart() {
    super.onStart();

    mAuth.addAuthStateListener(mAuthListener);
}

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 {
            // Google Sign In failed, update UI appropriately
            // ...
        }
    }
}

private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());

    AuthCredential credential = GoogleAuthProvider.getCredential(acct.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();
                    } else {
                        // If sign in fails, display a message to the user.
                        Log.w(TAG, "signInWithCredential:failure", task.getException());
                        Toast.makeText(GoogleSignIn.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                    }

                    // ...
                }
            });
}
公共类GoogleSignIn扩展AppCompative活动{
私人签名按钮谷歌签名;
专用静态最终int RC_SIGN_IN=1032;
私人GoogleapClient MGoogleapClient;
私人消防队;
私有FirebaseAuth.AuthStateListener mAuthListener;
私有最终静态字符串标记=“GOOGLESIGNIN”;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.google\u登录);
mAuth=FirebaseAuth.getInstance();
mAuthListener=new FirebaseAuth.AuthStateListener(){
@凌驾
AuthStateChanged上的公共void(@NonNull FirebaseAuth FirebaseAuth){
如果(firebaseAuth.getCurrentUser()!=null){
startActivity(新意图(GoogleSignIn.this,MainActivity.class));
}
}
};
googleSignIn=(SignInButton)findViewById(R.id.sign_in_按钮);
//配置谷歌登录
GoogleSignenOptions gso=新建GoogleSignenOptions.Builder(GoogleSignenOptions.DEFAULT\u登录)
.requestIdToken(getString(R.string.default\u web\u client\u id))
.requestEmail()
.build();
mGoogleApiClient=new-GoogleApiClient.Builder(getApplicationContext())
.enableautomanager(这是新的GoogleAppClient.OnConnectionFailedListener()){
@凌驾
public void onconnection失败(@NonNull ConnectionResult ConnectionResult){
}
})
.addApi(Auth.GOOGLE\u SIGN\u IN\u API,gso)
.build();
googleSignIn.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
签名();
}
});
}
@凌驾
受保护的void onStart(){
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
}
私人无效签名(){
意向符号=Auth.googlesignianpi.getsignient(mgoogleapclient);
startActivityForResult(签名、注册);
}
@凌驾
ActivityResult上的公共void(int请求代码、int结果代码、意图数据){
super.onActivityResult(请求代码、结果代码、数据);
//从GoogleSignInApi.getsigninent(…)启动Intent返回的结果;
if(requestCode==RC\u登录){
GoogleSignInResult结果=Auth.GoogleSignInApi.getSignInResultFromIntent(数据);
if(result.issucess()){
//Google登录成功,通过Firebase验证
GoogleSignInAccount account=result.getSignInAccount();
firebaseAuthWithGoogle(账户);
}否则{
//Google登录失败,请适当更新UI
// ...
}
}
}
私有void firebaseAuthWithGoogle(谷歌签名帐户){
Log.d(标记为“firebaseAuthWithGoogle:+acct.getId());
AuthCredential credential=GoogleAuthProvider.getCredential(acct.getIdToken(),null);
mAuth.SIGNWITH凭证(凭证)
.addOnCompleteListener(这是新的OnCompleteListener(){
@凌驾
未完成的公共void(@NonNull任务){
if(task.issusccessful()){
//登录成功,使用登录用户的信息更新UI
Log.d(标记“signInWithCredential:success”);
FirebaseUser=mAuth.getCurrentUser();
}否则{
//如果登录失败,则向用户显示消息。
w(标记“signInWithCredential:failure”,task.getException());
Toast.makeText(GoogleSignIn.this,“身份验证失败”,
吐司。长度(短)。show();
}
// ...
}
});
}

}我找到了错误,甚至找到了解决方法

问题在于sha1指纹。我能够使用测试设备成功登录到我的应用程序,因为我给出了调试sha1指纹,在哪里发布apk我需要发布sha1证书