我正在使用需要使用Firebase进行用户身份验证的android应用程序。我创建了一个测试活动,其中只有两个用于用户身份验证的字段(电子邮件和密码)。但是每次我输入电子邮件和密码并单击注册按钮时,都会显示吐司“无法注册”
这是我的注册活动:
package com.example.u.locationtracker;
import android.app.ProgressDialog;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
public class Register extends AppCompatActivity implements View.OnClickListener {
private EditText eemail, epass;
private Button bregist;
private ProgressDialog progressDialog;
private FirebaseAuth firebaseAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
progressDialog = new ProgressDialog(this);
firebaseAuth = FirebaseAuth.getInstance();
eemail = (EditText) findViewById(R.id.etemail);
epass = (EditText) findViewById(R.id.etpass);
bregist = (Button) findViewById(R.id.btnreg);
bregist.setOnClickListener(this);
}
private void registerUser() {
String Email = eemail.getText().toString().trim();
String Pass = epass.getText().toString().trim();
if (TextUtils.isEmpty(Email)) {
Toast.makeText(getApplicationContext(), "Enter the Email First",
Toast.LENGTH_LONG).show();
return;
}
if (TextUtils.isEmpty(Pass)) {
Toast.makeText(getApplicationContext(), "Enter the Password First",
Toast.LENGTH_LONG).show();
return;
}
progressDialog.setMessage("Signing in");
progressDialog.show();
firebaseAuth.createUserWithEmailAndPassword(Email, Pass)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Toast.makeText(getApplicationContext(), "Registration Successfull",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Can not Registered",
Toast.LENGTH_LONG).show();
}
}
});
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnreg:
registerUser();
break;
}
}
}
应用程序级别buld.gradle在这里:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.u.locationtracker"
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.1'
}
apply plugin: 'com.google.gms.google-services'
android studio也在此行显示错误,但可以正常工作:
implementation 'com.android.support:appcompat-v7:28.0.0'
我希望有人可以帮助我解决这个问题