Reputation: 439
I have an image in the database, which has a predefined path. I would conduct the query with Datasnapshot and see if the path is the path that I determine, then move on to the next step, which will be responsible for saving a new photo without deleting the old one which is default image and stays in Firebase Storage. If it is not the expected URL, then yes, execute the process that deletes the firebase image.
Currently you are ignoring my query and are already going to the next step which is to remove the image. How can I check this URL and if there is no task?
Code:
*fotoEmpresaDB = FirebaseDatabase.getInstance().getReference().child("Empresas").child(user_id).child("foto_capa");*/
fotoEmpresaDB.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if ( dataSnapshot.equals("https://firebasestorage.googleapis.com/v0/b/name-database/Default%2Fprofiledefault.jpg?alt=media&token=ad1ce6b7-1195-40fa-a88a-affade7517b0") ){
/*Method that saves image without deleting the previous image*/
salvarDadosImagem();
} else {
mProgress.setMessage("Deleting image....");
mProgress.show();
mProgress.setCancelable(false);
String url = dataSnapshot.getValue(String.class);
mStorageUrl = FirebaseStorage.getInstance().getReferenceFromUrl(url);
mStorageUrl.delete().addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
salvarDadosImagem();
}
I have tried as: datasnapshot.hashChild("URL").
This error happens: Invalid Firebase Database path: Firebase Database paths must not contain '.', '#', '$', '[', or ']'
Upvotes: 0
Views: 971
Reputation: 598847
Not really sure I understand what you're trying to do, but here are the two most likely answers.
To detect if the value matches what you're looking for dataSnapshot.getValue(String.class).equals("https://REST_OF_YOUR_URL")
To detect if the node has any value (so: if it exists): dataSnapshot.exists()
Upvotes: 1
Reputation: 439
solution:
fotoEmpresaDB.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String url = dataSnapshot.getValue(String.class);
if ( url.contentEquals("https: URL") ){
/*Method that saves image without deleting the previous image*/
salvarDadosImagem();
} else {
Upvotes: 0