虽然我输入了正确的电子邮件和密码,但我的代码没有读取任何声明。 firebase连接已经定义,数据库中已经存在电子邮件和密码。
这是我的activity_login代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_login"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.nani.mrt.Login">
<ImageView
android:id="@+id/icon1"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="@drawable/ic_navlogo"
android:layout_width="100dp"
android:layout_height="100dp" />
<android.support.design.widget.TextInputLayout
android:layout_below="@+id/icon1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/login_input_email"
>
<EditText
android:id = "@+id/login_email"
android:hint="Enter your email"
android:inputType="textCapWords"
android:maxLines="1"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_below="@+id/login_input_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/login_input_password"
>
<EditText
android:id = "@+id/login_password"
android:hint="Enter your password"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:inputType = "textPassword"
android:maxLines="1"
/>
</android.support.design.widget.TextInputLayout>
<Button
android:text="SIGN IN"
android:background="#263238"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="login"
android:id="@+id/btnsignin"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_below="@+id/btnsignin"
android:text="FORGOT PASSWORD?"
android:clickable="true"
android:layout_centerHorizontal="true"
android:textStyle="bold"
style="@style/Widget.AppCompat.Button.Borderless"
android:textColor="@color/colorPrimaryDark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnforgot"
android:onClick="forgotpassword" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/btnforgot"
android:id="@+id/login_layout_or"
android:gravity="center"
android:orientation="horizontal">
<View
android:layout_width="200dp"
android:layout_height="1dp"
android:layout_margin="5dp"
android:background="#c4c8c9" />
<TextView
android:padding="5dp"
android:text="OR"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<View
android:layout_width="200dp"
android:layout_height="1dp"
android:layout_margin="5dp"
android:background="#c4c8c9" />
</LinearLayout>
<TextView
android:layout_below="@+id/login_layout_or"
android:text="Register an account" android:clickable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="register"
android:layout_centerHorizontal="true"
android:textStyle="bold"
style="@style/Widget.AppCompat.Button.Borderless"
android:textColor="@color/colorPrimaryDark"
android:id="@+id/register"
/>
这是我的登录活动代码
公共类登录扩展AppCompatActivity实现了View.OnClickListener {
private Button btnsignin;
private EditText editTextemail, editTextpassword;
private TextView register, btnforgot;
private ProgressDialog progressDialog;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener firebaseAuthListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
btnsignin = (Button) findViewById(R.id.btnsignin);
btnforgot = (TextView) findViewById(R.id.btnforgot);
editTextemail = (EditText) findViewById(R.id.login_email);
editTextpassword = (EditText) findViewById(R.id.login_password);
register = (TextView) findViewById(R.id.register);
btnsignin.setOnClickListener(this);
btnforgot.setOnClickListener(this);
register.setOnClickListener(this);
mAuth = FirebaseAuth.getInstance();
}
@Override
public void onClick(View view) {
if (view == btnsignin) {
// signinUser(editTextemail.getText().toString(),editTextpassword.getText().toString());
String email = editTextemail.getText().toString().trim();
final String password = editTextpassword.getText().toString().trim();
if (TextUtils.isEmpty(email)) {
Toast.makeText(getApplicationContext(), "Enter email address!", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(password)) {
Toast.makeText(getApplicationContext(), "Enter password!", Toast.LENGTH_SHORT).show();
return;
}
//authenticate user
mAuth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(Login.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
// there was an error
if (password.length() < 6) {
Toast.makeText(Login.this, "Try Again", Toast.LENGTH_LONG).show();
// editTextpassword.setError(getString(R.string.minimum_password));
}
} else {
Intent intent = new Intent(Login.this, HomeNavigation.class);
intent.putExtra("usernamekey", editTextemail.getText().toString());
startActivity(intent);
finish();
}
}
});
}
if (view == btnforgot) {
Intent intent = new Intent(Login.this, ForgotPassword.class);
startActivity(intent);
}
if (view == register) {
Intent intent = new Intent(Login.this, RegisterAs.class);
startActivity(intent);
}
}