单击登录按钮后,活动停止并显示以下错误。该应用程序可在android 7.0上正常运行,但在单击“登录”按钮
后会在android 5.0.1上终止这是logcat中显示的错误
W/ResourcesManager: getTopLevelResources: null for user 0
V/FA: onActivityCreated
V/FA: Activity resumed, time: 88013293
D/FA: Logging event (FE): screen_view(_vs),
Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=SignIn,
firebase_previous_id(_pi)=-1673552764105460140, firebase_screen_class(_sc)=SignInHubActivity, firebase_screen_id(_si)=-1673552764105460139}]
D/PhoneWindow: *FMB* installDecor mIsFloating : false
*FMB* installDecor flags : 8454400
D/DisplayManager: DisplayManager()
D/PhoneWindow: *FMB* isFloatingMenuEnabled mFloatingMenuBtn : null
*FMB* isFloatingMenuEnabled return false
V/FA: Screen exposed for less than 1000 ms. Event not sent. time: 174
Activity paused, time: 88013462
I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@caff020 time:33912307
E/OpenGLRenderer: SFEffectCache:clear(), mSize = 0
这是代码
public class SignIn extends AppCompatActivity {
GoogleApiClient mGoogleApiClient;
private FirebaseAuth mAuth;
FirebaseAuth.AuthStateListener mAuthListner;
private DatabaseReference mdatabase;
private SignInButton btn_signin;
private GoogleSignInClient mGoogleSignInClient;
private static final int RC_SIGN_IN = 9001;
ProgressDialog progressDialog ;
protected void onStart()
{
super.onStart();
FirebaseUser currentUser = mAuth.getCurrentUser();
progressDialog = ProgressDialog.show(this,"Loading","Please Wait",false,false);
updateUI(currentUser);
}
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_in);
btn_signin = (SignInButton) findViewById(R.id.sign_in_button);//play version 12685022
btn_signin.setVisibility(GONE);
mAuth = FirebaseAuth.getInstance();
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
btn_signin.setOnClickListener(SignInListener);
}
private void signIn() {
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
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) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
try {
// Google Sign In was successful, authenticate with Firebase
GoogleSignInAccount account = task.getResult(ApiException.class);
firebaseAuthWithGoogle(account);
} catch (ApiException e) {
// Google Sign In failed, update UI appropriately
Log.w("TAG", "Google sign in failed", e);
// [START_EXCLUDE]
// [END_EXCLUDE]
}
}else{
Toast.makeText(SignIn.this,"hello",Toast.LENGTH_LONG).show();
}
}
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
Log.d("TAG", "firebaseAuthWithGoogle:" + acct.getId());
// [START_EXCLUDE silent]
progressDialog = ProgressDialog.show(this,"Loading","Please
Wait",false,false);
// [END_EXCLUDE]
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();
updateUI(user);
} else {
// If sign in fails, display a message to the user.
Log.w("TAG", "signInWithCredential:failure", task.getException());
//Snackbar.make(findViewById(R.layout.activity_sign_in), "Authentication Failed.", Snackbar.LENGTH_SHORT).show();
//Log.w("TAG", "signInWithCredential:failure", task.getException());
Toast.makeText(getApplicationContext(), "Authentication Failed.", Toast.LENGTH_SHORT).show();
updateUI(null);
}
// [START_EXCLUDE]
progressDialog.dismiss();
// [END_EXCLUDE]
}
});
}
private void updateUI(FirebaseUser user) {
progressDialog.dismiss();
if (user != null) {
Toast.makeText(this, user.getEmail() + "\n" + user.getDisplayName(), Toast.LENGTH_LONG);
// mStatusTextView.setText(getString(R.string.google_status_fmt, user.getEmail()));
//mDetailTextView.setText(getString(R.string.firebase_status_fmt, user.getUid()));
findViewById(R.id.sign_in_button).setVisibility(View.GONE);
//findViewById(R.id.sign_out_and_disconnect).setVisibility(View.VISIBLE);
} else {
//mStatusTextView.setText(R.string.signed_out);
//mDetailTextView.setText(null);
findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
//findViewById(R.id.sign_out_and_disconnect).setVisibility(View.GONE);
}
}
private View.OnClickListener SignInListener=new View.OnClickListener() {
@Override
public void onClick(View v) {
signIn();
}
};
}