我正在尝试使用Firebase创建一个登录应用,并且在设计方面存在注册方面的问题。当我构建并运行我的应用程序时,它会构建并启动正常,但是当我在模拟器上使用该应用程序并单击“注册”按钮时,该按钮将无响应。我可以单击该按钮,但是onClickListener未被激活。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_registration);
setupUIViews();
mAuth = FirebaseAuth.getInstance();
sign.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (validate() ) {
String user_email = email.getText().toString().trim();
String user_Password = pass.getText().toString().trim();
registerUser(user_email, user_Password);
}
}
});
already.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(Registration.this, Login.class));
}
});
}
public void registerUser(String x, String y){
mAuth.createUserWithEmailAndPassword(x, y)
.addOnCompleteListener(Registration.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Toast.makeText(Registration.this, "Registration Complete", Toast.LENGTH_SHORT).show();
startActivity(new Intent(Registration.this, Login.class));
} else {
Toast.makeText(Registration.this, "Registration failed" + task.getException().getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
}
private void setupUIViews() {
user = (EditText) findViewById(R.id.editText5);
email = (EditText) findViewById(R.id.Email);
pass = (EditText) findViewById(R.id.etPassword);
phone = (EditText) findViewById(R.id.Pnumber);
first = (EditText) findViewById(R.id.FirstName);
last = (EditText) findViewById(R.id.LastName);
sign = (Button) findViewById(R.id.button15);
already = (TextView) findViewById(R.id.textView);
}
private Boolean validate(){
Boolean result = false;
String name = first.getText().toString();
String email1 = email.getText().toString();
String username = user.getText().toString();
String lastt = last.getText().toString();
String password = pass.getText().toString();
String phone1 = phone.getText().toString();
if (name.isEmpty() || email1.isEmpty() || lastt.isEmpty() ||
password.isEmpty() || phone1.isEmpty() || username.isEmpty()) {
Toast.makeText(Registration.this, "Please Fill in all fields ", Toast.LENGTH_SHORT).show();
} else {
result = true;
}
return result;
}
}
当我将google play添加到模拟器中时,此问题开始。在此之前,我的登录按钮只会生成我已嵌入到validate函数中的错误消息。签名按钮应该调用validate函数,然后在我的Firebase应用程序中创建一个新用户。当我检查logcat时出现此错误:
17856-17889/com.example.habib.linx E/FirebaseInstanceId: Google Play services missing or without correct permission.