你好,我的问题是我已经实现了firebaseUI身份验证 与谷歌和电话号码,并发送电子邮件给我,如何验证仅电子邮件 当用户使用电子邮件登录时,我不知道写在哪里,原因可能是 应用程序由带firebaseUI的登录页面和之后的活动组成 这是主页,因此如果用户使用,我何时可以控制天气 已验证的电子邮件以传递到主页,或者如果未通过验证,则应该 首先先进行验证
public class MainActivity extends AppCompatActivity {
private String id;
private static final int RC_SIGN_IN = 1;
private FirebaseDatabase mFirebaseDatabase;
private DatabaseReference mDatabaseReference;
private FirebaseAuth mFirebaseAuth;
private FirebaseUser user;
private boolean flag = true;
static String LoggedIn_User_Email;
private FirebaseAuth.AuthStateListener mAuthStateListner;
List<AuthUI.IdpConfig> providers = Arrays.asList(
new AuthUI.IdpConfig.EmailBuilder().build(),
new AuthUI.IdpConfig.PhoneBuilder().build(),
new AuthUI.IdpConfig.GoogleBuilder().build()
);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mFirebaseDatabase = FirebaseDatabase.getInstance();
mDatabaseReference = mFirebaseDatabase.getReference("Users");
mFirebaseAuth = FirebaseAuth.getInstance();
mAuthStateListner = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
Intent intent = new Intent(MainActivity.this, SignIn.class);
startActivity(intent);
} else { //signing in
startActivityForResult(AuthUI.getInstance().
createSignInIntentBuilder().
setAvailableProviders(providers).
setIsSmartLockEnabled(false).
setLogo(R.drawable.sa_logo).
build(), RC_SIGN_IN);
}
}
};
//one signal code
OneSignal.startInit(this)
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
.setNotificationOpenedHandler(new ExampleNotificationOpenedHandler(getApplication()))
.setNotificationReceivedHandler(new ExampleNotificationReceivedHandler(getApplication()))
.unsubscribeWhenNotificationsAreDisabled(true)
.init();
//////
}
@Override
protected void onStart() {
super.onStart();
mFirebaseAuth.addAuthStateListener(mAuthStateListner);
}
@Override
protected void onPause() {
super.onPause();
mFirebaseAuth.removeAuthStateListener(mAuthStateListner);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
if (resultCode == RESULT_OK) {
// Read from the database
user = FirebaseAuth.getInstance().getCurrentUser();
mDatabaseReference = mFirebaseDatabase.getReference("Users");
mDatabaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (!dataSnapshot.exists()) {
Intent intent = new Intent(MainActivity.this, Welcome.class);
startActivity(intent);
} else {
FirebaseUser currentUser = mFirebaseAuth.getCurrentUser();
OneSignal.sendTag("User_ID", user.getUid());
for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
Users u = postSnapshot.getValue(Users.class);
if (u.getID().equals(currentUser.getUid())) {
Intent intent = new Intent(getApplicationContext(), SignIn.class);
LoggedIn_User_Email = u.getID();
startActivity(intent);
break;
} else {
flag = false;
}
if (flag == false) {
Intent intent = new Intent(MainActivity.this, Welcome.class);
startActivity(intent);
}
}
}
user = FirebaseAuth.getInstance().getCurrentUser();
//
// if (user.isEmailVerified())
// {
// user.sendEmailVerification().addOnCompleteListener(new OnCompleteListener<Void>() {
// @Override
// public void onComplete(@NonNull Task<Void> task)
// {
// if (task.isSuccessful())
// {
// Log.e("", "Verification email sent to " + user.getEmail());
//
// } else
// {
// Log.e("", "sendEmailVerification failed!", task.getException());
// }
// }
// });
// }
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
Log.w("", "Failed to read value.", error.toException());
}
});
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, "signed in cancelled", Toast.LENGTH_LONG).show();
finish();
System.exit(0);
}
}
}
}