I'm trying to create a Activity
where you can set a profile image by uploading it to the Storage
of Firebase
from the gallery through a upload button, and the idea is to remain saved in that activity, but when going on activity, this photo is reset by the one it initially had in gray.
I would like to know how I can do to save the changes in the profile photo and that it will not be changed unless another photo is selected.
//pasa la foto al storage
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//VERIFICA QUE SE HAYA SELECCIONADO UNA FOTO
if (requestCode == GALLERY_INTENT && resultCode == RESULT_OK) {
//si todo sale bien entonces cargamos la barra de espera
progressDialog.setTitle("Subiendo...");
progressDialog.setMessage("Subiendo Foto");
progressDialog.setCancelable(false);//para que al clickear fuera del cuadrado no se salga
progressDialog.show();
Uri uri = data.getData();
//recibe la ruta de la foto o el nombre del archivo
final StorageReference filePath = miStorageReferenceImagen.child("fotos").child(uri.getLastPathSegment());
//sube la foto a la carpeta en storage que acabamos de crear
filePath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
progressDialog.dismiss();//finaliza la barra de carga
//OBTIENE EL URI DE LA FOTO
filePath.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
//la librería glide se añade al gradle app y al project, para guardar imágenes en caché etc
Glide.with(getBaseContext())
.load(uri).into(civPerfil1);//con fit center y .centercrop se acomoda la imagen pero solo sirve para los images views
Toast.makeText(getBaseContext(), uri.toString(), Toast.LENGTH_SHORT).show();
}
});
}
});
}
}
//metodo subir foto
public void subirFoto(View v) {
Intent intent = new Intent(Intent.ACTION_PICK);//escoger imagen de la galería
intent.setType("image/*");//abarca todos los formatos de images
startActivityForResult(intent, GALLERY_INTENT);
}