0

El codigo que me produce error es el siguiente

public void createOrUpdateProfileWithImage(final Profile profile, Uri imageUri, final OnProfileCreatedListener onProfileCreatedListener) {
    String imageTitle = ImageUtil.generateImageTitle(UploadImagePrefix.PROFILE, profile.getId());
    UploadTask uploadTask = databaseHelper.uploadImage(imageUri, imageTitle);

    if (uploadTask != null) {
        uploadTask.addOnCompleteListener(task -> {
            if (task.isSuccessful()) {
                Uri downloadUrl = task.getResult().getDownloadUrl();
                LogUtil.logDebug(TAG, "successful upload image, image url: " + String.valueOf(downloadUrl));

                profile.setPhotoUrl(downloadUrl.toString());
                createOrUpdateProfile(profile, onProfileCreatedListener);

            } else {
                onProfileCreatedListener.onProfileCreated(false);
                LogUtil.logDebug(TAG, "fail to upload image");
            }

        });
    } else {
        onProfileCreatedListener.onProfileCreated(false);
        LogUtil.logDebug(TAG, "fail to upload image");
    }
}

...

1 respuesta 1

0

El reemplazo a este metodo deprecado es usar Task ya que ahora todas las operaciones de Firebase devuelven un Task

 UploadTask uploadTask = image_path.putFile(mainImageURI);

                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 image_path.getDownloadUrl();
                    }
                }).addOnCompleteListener(new OnCompleteListener<Uri>() {
                    @Override
                    public void onComplete(@NonNull Task<Uri> task) {
                        if (task.isSuccessful()){
                            Uri downloadUrl = task.getResult();
                            Log.i("URL : ", downloadUrl.toString());
                        }
                    }
                });
            }

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.