您好,我是android应用程序开发的新手。 我正在使用Android Studio版本3.0.1和Firebase。 **在此之前,我可以注册我的用户。** **但是最近我无法注册新用户。**
我该怎么办? 有人可以帮我吗?
这是我的代码段。
仅显示此“无法注册。请重试”
public class PSregister extends AppCompatActivity {
private Button buttonRegister;
private EditText editTextEmail;
private EditText editTextPassword;
private ImageButton mPSProfileImage;
private EditText mNameText;
private EditText mPhoneNoText;
private EditText mLocationText;
private EditText mSSM;
private TextView textViewSignIn;
private ProgressDialog progressDialog;
private FirebaseAuth firebaseAuth;
private Uri mImageUri = null;
private static final int GALLERY_REQUEST = 1;
private StorageReference mStorage;
private DatabaseReference mDatabase;
PSDA Helper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_psregister);
firebaseAuth = firebaseAuth.getInstance();
progressDialog = new ProgressDialog(this);
mStorage = FirebaseStorage.getInstance().getReference();
mDatabase = FirebaseDatabase.getInstance().getReference();
Helper = new PSDA(mDatabase);
mPSProfileImage = (ImageButton) findViewById(R.id.imageButton);
editTextEmail = (EditText) findViewById(R.id.psEmail);
editTextPassword = (EditText) findViewById(R.id.psPwd);
mNameText = (EditText) findViewById(R.id.psName);
mPhoneNoText = (EditText) findViewById(R.id.psPNum);
mLocationText = (EditText) findViewById(R.id.psAdd);
mSSM = (EditText) findViewById(R.id.SSMLicense);
buttonRegister = (Button) findViewById(R.id.buttonRegister);
textViewSignIn = (TextView) findViewById(R.id.textViewSignIn);
mPSProfileImage.setOnClickListener (new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT);
galleryIntent.setType("image/*");
startActivityForResult(galleryIntent, GALLERY_REQUEST);
}
});
buttonRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
registerUser();
}
});
textViewSignIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(v == textViewSignIn) {
//open login activity
startActivity(new Intent(PSregister.this,psLogin .class));
}
}
});
}
private void registerUser() {
final String email = editTextEmail.getText().toString().trim();
final String password = editTextPassword.getText().toString().trim();
final String name = mNameText.getText().toString().trim();
final String pNum = mPhoneNoText.getText().toString().trim();
final String loc = mLocationText.getText().toString().trim();
final String SSM= mSSM.getText().toString().trim();
if(TextUtils.isEmpty(email)){
//email empty
Toast.makeText(this, "Please enter email", Toast.LENGTH_SHORT).show();
return;
}
if(TextUtils.isEmpty(password)) {
//password empty
Toast.makeText(this, "Please enter password", Toast.LENGTH_SHORT).show();
return;
}
if(TextUtils.isEmpty(name)){
Toast.makeText(this,"Please enter name",Toast.LENGTH_SHORT).show();
return;
}
if(TextUtils.isEmpty(pNum)){
Toast.makeText(this,"Please enter phone number",Toast.LENGTH_SHORT).show();
return;
}
if(TextUtils.isEmpty(loc)){
Toast.makeText(this,"Please enter address",Toast.LENGTH_SHORT).show();
return;
}
if(TextUtils.isEmpty(SSM)){
Toast.makeText(this,"Please enter SSM License",Toast.LENGTH_SHORT).show();
return;
}
//if validation ok
//will show progress bar
progressDialog.setMessage("Registering User...");
progressDialog.show();
firebaseAuth.createUserWithEmailAndPassword(email,password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
public void onComplete(@NonNull Task<AuthResult> task) {
//checking if successful
if (task.isSuccessful()) {
//registered
String psId = firebaseAuth.getCurrentUser().getUid();
startPosting(psId, email, password);
Toast.makeText(PSregister.this, "Registered Successfully", Toast.LENGTH_LONG).show();
finish();
startActivity(new Intent(getApplicationContext(), psLogin.class));
} else {
Toast.makeText(PSregister.this, "Could not register. Please try again", Toast.LENGTH_SHORT).show();
}
progressDialog.dismiss();
}
});
}
private void startPosting(final String psId, final String Email, final String password) {
final String psname = mNameText.getText().toString();
final String psPNum = mPhoneNoText.getText().toString();
final String psAdd = mLocationText.getText().toString();
final String psSSM = mSSM.getText().toString();
if(!TextUtils.isEmpty(psname) && !TextUtils.isEmpty(psPNum) && !TextUtils.isEmpty(psAdd) && !TextUtils.isEmpty(psSSM)
&& mImageUri != null){
StorageReference filepath = mStorage.child("psimageProfile").child(mImageUri.getLastPathSegment());
filepath.putFile(mImageUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Uri downloadUrl = taskSnapshot.getDownloadUrl();
DatabaseReference newPost = mDatabase.push();
PS ps = new PS(downloadUrl.toString(),psId, Email, password, psname, psPNum, psAdd, psSSM );
Helper.CreatePS(ps, psId);
}
});
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == GALLERY_REQUEST && resultCode == RESULT_OK) {
mImageUri = data.getData();
mPSProfileImage.setImageURI(mImageUri);
}
}
}
答案 0 :(得分:0)
您的密码必须超过6个字符或数字,并且还要求输入强度高的密码 密码。
电子邮件每次都必须是唯一的。