Last active
August 7, 2020 06:46
-
-
Save crazy-diya/24cb2015ab8ead16f1cd7aa1c97c2e2c to your computer and use it in GitHub Desktop.
another way Store image in to Stroagefirebase and get downloadlink in Android Studio Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final StorageReference filePath = storageReference.child(messagePushId + "." + "jpg"); | |
uploadTask = filePath.putFile(fileUri); | |
uploadTask.continueWithTask(new Continuation() { | |
@Override | |
public Object then(@NonNull Task task) throws Exception { | |
if (!task.isSuccessful()){ | |
throw task.getException(); | |
} | |
return filePath.getDownloadUrl(); | |
} | |
}).addOnCompleteListener(new OnCompleteListener<Uri>() { | |
@Override | |
public void onComplete(@NonNull Task<Uri> task) { | |
if (task.isSuccessful()){ | |
Uri downloadUrl = task.getResult(); | |
myUrl = downloadUrl.toString(); | |
Map messageTextBody = new HashMap(); | |
messageTextBody.put("message",myUrl); | |
messageTextBody.put("name",fileUri.getLastPathSegment()); | |
messageTextBody.put("type", checker); | |
messageTextBody.put("from", messageSenderId); | |
messageTextBody.put("to", getmessageReciverId); | |
messageTextBody.put("messageID", messagePushId); | |
messageTextBody.put("time", saveCurrentTime); | |
messageTextBody.put("date", saveCurrentDate); | |
Map messageBodyDetails = new HashMap(); /**Meeka wenuwata mulin than waladi baawitha kala wage puluwan database ekata add karanna*/ | |
messageBodyDetails.put(messageSenderRef + "/" + messagePushId, messageTextBody); | |
messageBodyDetails.put(messageReceiverRef + "/" + messagePushId, messageTextBody); | |
RootRef.updateChildren(messageBodyDetails).addOnCompleteListener(new OnCompleteListener() { | |
@Override | |
public void onComplete(@NonNull Task task) { | |
if (task.isSuccessful()){ | |
loadingBar.dismiss(); | |
Toast.makeText(ChatActivity.this, "Message Sent Succesfully!", Toast.LENGTH_SHORT).show(); | |
} | |
else{ | |
loadingBar.dismiss(); | |
Toast.makeText(ChatActivity.this, "Error!", Toast.LENGTH_SHORT).show(); | |
} | |
MessageInputText.setText(null); | |
} | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment