это код, который я использую для регистрации, но операция регистрации прослушивателя createUserWithEmailAndPassword onComplete автоматически переходит к операции входа в систему перед выполнением uploadFile, в logcat нет ошибки:
public class RegestrationActivity extends BaseActivity implements View.OnClickListener {
ActivityRegestrationBinding mBinding;
FirebaseStorage mStorage;
private File selectedImage;
private FirebaseAuth auth;
private DatabaseReference mDatabase;
public static void launch(AppCompatActivity activity) {
Intent intent = new Intent(activity, RegestrationActivity.class);
activity.startActivity(intent);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_regestration);
initViews();
}
private void initViews() {
auth = FirebaseAuth.getInstance();
mStorage = FirebaseStorage.getInstance();
mDatabase = FirebaseDatabase.getInstance().getReference();
mBinding.btnSignUp.setOnClickListener(this);
mBinding.ivPic.setOnClickListener(this);
mBinding.tvLogIn.setOnClickListener(this);
}
public void selectImageDialog() {
Dexter.withActivity(this)
.withPermissions(
Manifest.permission.CAMERA,
Manifest.permission.WRITE_EXTERNAL_STORAGE
).withListener(new MultiplePermissionsListener() {
@Override
public void onPermissionsChecked(MultiplePermissionsReport report) {
if (report.areAllPermissionsGranted()) {
final CharSequence[] charGender = {getString(R.string.check_in_detail_option_camera), getString(R.string.check_in_detail_option_gallery)};
AlertDialog.Builder alert = new AlertDialog.Builder(RegestrationActivity.this);
alert.setTitle(getString(R.string.check_option));
alert.setItems(charGender, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
EasyImage.openCamera(RegestrationActivity.this, 0);
} else if (which == 1) {
EasyImage.openGallery(RegestrationActivity.this, 0);
}
}
});
alert.show();
} else if (!report.areAllPermissionsGranted()) {
if (report.isAnyPermissionPermanentlyDenied()) {
showPermissionSettingDialog(getResources().getString(R.string.permission_never_ask_message));
} else {
showPermissionDeniedDialog(getResources().getString(R.string.permission_denied_message));
}
} else if (report.isAnyPermissionPermanentlyDenied()) {
showPermissionSettingDialog(getResources().getString(R.string.permission_never_ask_message));
}
}
@Override
public void onPermissionRationaleShouldBeShown(List<PermissionRequest> permissions, PermissionToken token) {
Logger.e("show Rationale");
token.continuePermissionRequest();
}
}).check();
}
public void showPermissionSettingDialog(String message) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.permission_required);
builder.setMessage(message);
builder.setPositiveButton(R.string.app_settings, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setData(Uri.parse("package:" + getPackageName()));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
startActivity(intent);
dialog.dismiss();
}
});
builder.setNegativeButton(R.string.str_cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
stopProgress();
}
});
builder.create().show();
}
public void showPermissionDeniedDialog(String message) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.permission_required);
builder.setMessage(message);
builder.setPositiveButton(R.string.re_try, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
selectImageDialog();
}
});
builder.setNegativeButton(R.string.i_am_sure, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
EasyImage.handleActivityResult(requestCode, resultCode, data, this, new DefaultCallback() {
@Override
public void onImagePickerError(Exception e, EasyImage.ImageSource source, int type) {
e.printStackTrace();
}
@Override
public void onImagesPicked(List<File> imageFiles, EasyImage.ImageSource source, int type) {
onPhotosReturned(imageFiles);
}
@Override
public void onCanceled(EasyImage.ImageSource source, int type) {
if (source == EasyImage.ImageSource.CAMERA) {
File photoFile = EasyImage.lastlyTakenButCanceledPhoto(RegestrationActivity.this);
if (photoFile != null) photoFile.delete();
}
}
});
}
private void onPhotosReturned(List<File> returnedPhotos) {
Logger.Error("Path : " + returnedPhotos.get(0).getAbsolutePath());
selectedImage = returnedPhotos.get(0);
try {
selectedImage = new Compressor(this).compressToFile(selectedImage);
glideLoader.loadCircleUserImageFromFile(selectedImage, mBinding.ivPic);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.btnSignUp:
isValid();
break;
case R.id.ivPic:
selectImageDialog();
break;
case R.id.tvLogIn:
finish();
break;
}
}
public void isValid() {
if (selectedImage==null) {
showErrorSnackBar(getString(R.string.validation_select_image));
} else if (mBinding.etName.getText().toString().trim().isEmpty()) {
showErrorSnackBar(getString(R.string.validation_empty_name));
mBinding.etName.requestFocus();
} else if (mBinding.etEmail.getText().toString().trim().isEmpty()) {
showErrorSnackBar(getString(R.string.validation_empty_email));
mBinding.etEmail.requestFocus();
} else if (!Patterns.EMAIL_ADDRESS.matcher(mBinding.etEmail.getText().toString().trim()).matches()) {
showErrorSnackBar(getString(R.string.validation_invalid_email));
mBinding.etEmail.requestFocus();
} else if (mBinding.etPassword.getText().toString().trim().isEmpty()) {
showErrorSnackBar(getString(R.string.validation_password));
mBinding.etPassword.requestFocus();
} else if (mBinding.etPassword.getText().toString().trim().length() < 6) {
showErrorSnackBar(getString(R.string.validation_short_password));
mBinding.etPassword.requestFocus();
} else if (!isConnectedToInternet()) {
showSnackBar(getString(R.string.no_internet));
} else {
fireBaseRegistration();
}
}
private void fireBaseRegistration() {
showProgress();
//create user
auth.createUserWithEmailAndPassword(mBinding.etEmail.getText().toString().trim(), mBinding.etPassword.getText().toString().trim())
.addOnCompleteListener(RegestrationActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (!task.isSuccessful()) {
Toast.makeText(RegestrationActivity.this, "Authentication failed." + task.getException().getLocalizedMessage(),
Toast.LENGTH_SHORT).show();
} else {
uploadFile();
}
}
});
}
private void uploadFile() {
Uri file = Uri.fromFile(selectedImage);
final StorageReference ref = mStorage.getReference().child(" ProfilePics/" + auth.getUid() + "/" + auth.getUid() + ".jpg");
UploadTask uploadTask = ref.putFile(file);
Task<Uri> urlTask = uploadTask.continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {
@Override
public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
if (!task.isSuccessful()) {
throw task.getException();
}
return ref.getDownloadUrl();
}
}).addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
if (task.isSuccessful()) {
Uri downloadUri = task.getResult();
Map<String, Object> newUserDetails = new HashMap<String, Object>();
newUserDetails.put("email", mBinding.etEmail.getText().toString().trim());
newUserDetails.put("name", mBinding.etName.getText().toString().trim());
newUserDetails.put("profileurl", downloadUri.toString());
mDatabase.child("users").child(auth.getUid()).setValue(newUserDetails);
stopProgress();
new MessageDialog(getApplicationContext())
.setTitle(getString(R.string.app_name))
.setMessage(getString(R.string.account_created_successfully))
.setPositiveButton(getString(R.string.str_Ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
finish();
}
}).show();
} else {
stopProgress();
showErrorSnackBar(task.getException().getMessage());
}
}
});
}
}