我想整合谷歌登錄我的應用程序,但它沒有追求我到另一個活動,它顯示唯一的身份驗證在模擬器中失敗,但是當我在真實設備上測試它時,應用程序停止點擊谷歌標誌按鈕。這是我下面谷歌登錄身份驗證失敗
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import com.google.android.gms.auth.api.Auth;
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 googleact extends AppCompatActivity {
SignInButton button;
FirebaseAuth firebaseauth;
private final static int RC_SIGN_IN=2;
GoogleApiClient mGoogleApiClient;
FirebaseAuth.AuthStateListener mAuthListener;
@Override
protected void onStart() {
super.onStart();
firebaseauth.addAuthStateListener(mAuthListener);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_googleact);
button =(SignInButton) findViewById(R.id.googlebtn);
firebaseauth = FirebaseAuth.getInstance();
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
signIn();
}
});
mAuthListener=new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
if (firebaseAuth.getCurrentUser() !=null){
startActivity(new Intent(googleact.this, gprofile.class));
}
}
};
// Configure Google Sign In
GoogleSignInOptions gso = new
GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
// Build a GoogleApiClient with access to the Google Sign-In API and
the
// options specified by gso.
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, new
GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(@NonNull ConnectionResult
connectionResult) {
Toast.makeText(googleact.this,"something went wrong",
Toast.LENGTH_SHORT).show();
}
})
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
}
// Configure Google Sign In
//GoogleSignInOptions gso = new
GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
// .requestIdToken(getString(R.string.default_web_client_id))
// .requestEmail()
// .build();
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(googleact.this,"AUTH WENT WRONG",
Toast.LENGTH_SHORT).show();
}
}
}
private void firebaseAuthWithGoogle(GoogleSignInAccount account) {
AuthCredential credential =
GoogleAuthProvider.getCredential(account.getIdToken(), null);
firebaseauth.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 = firebaseauth.getCurrentUser();
// updateUI(user);
} else {
// If sign in fails, display a message to the user.
Log.w("TAG", "signInWithCredential:failure",
task.getException());
Toast.makeText(googleact.this, "Authentication
failed.",
Toast.LENGTH_SHORT).show();
// updateUI(null);
}
// ...
}
});
}
}
這裏下面
代碼在logcat的 07-02 13:55:11.367 24547-24547 /? I/art:不是延遲啓用-Xcheck:jni (已啓用) 07-02 13:55:11.367 24547-24547 /? W /藝術:意外CPU變體用於使用X86 的默認值:86 07-02 13:55:11.793 24547-24547/com.example.roomsarehere.foodishere W /系統: 類加載器引用未知路徑: /數據/應用/com.example.roomsarehere.foodishere-1/lib/x86 07-02 13:55:12.086 24547-24571/com.example.roomsarehere.foodishere I/DynamiteModule:考慮本地模塊com.google.android.gms。標誌:2 和 遠程模塊com.google.android.gms.flags:0 07-02 13:55:12.086 24547-24571/com.example.roomsarehere.foodishere I/DynamiteModule:選定本地版本com。 google.android.gms.flags 07-02 13:55:12.131 24547-24571/com.example.roo msarehere.foodishere W/System: 類加載器引用未知路徑: 07-02 13:55:12.136 24547-24571/com.example.roomsarehere.foodishere W/System: ClassLoader引用未知路徑:/ system/priv- app/PrebuiltGmsCore/lib/x86 012/07-02 13:55:12.148 24547-24571/com.example.roomsarehere.foodishere D/ApplicationLoaders:忽略Vulkan圖層搜索路徑/ system/priv- app/PrebuiltGmsCore/lib/x86:/system/priv- 命名空間0xa787a090 07-02 13:55:12.194 24547-p/app/PrebuiltGmsCore/24547/com.example.roomsarehere.foodishere I/FA:App 測量正在啓動,版本:11020 07-02 13:55:12.195 24547-24547/com.example.roomsarehere.foodishere I/FA:至 啓用調試日誌記錄運行:adb shell setprop log.tag.FA VERBOSE 07-02 13:55:12.222 24547 -24571/com.example.roomsarehere.foodishere W/DynamiteModule:找不到本地模塊描述符類 com.google.android.gms.crash 未找到。 07-02 13:55:12.265 24547-24547/com.example.roomsarehere.foodishere V/FA: 集啓用
crash log,please? – jagapathi
先生應用程序在真實設備上崩潰,但內部模擬器顯示吐司「身份驗證失敗」意味着任務未完成。 –