Task<Uri>
,请尝试一下。通过不建议使用此getMetadata().getReference().getDownloadUrl()
,建议您阅读此Upload-files firebase对于我在聊天室com.google.android.gms.tasks.zzu@d55ef5
中发送的每张图像,这都会返回我>
以下是我的代码:
<< >@Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == 1 && resultCode == RESULT_OK){ Uri uriImagen = data.getData(); storageReference = storage.getReference("chat_images");//El nombre de la carpeta en la que voy a guardar las imagenes final StorageReference photoReference = storageReference.child(uriImagen.getLastPathSegment()); //Obtenemos como un id de la imagen que la diferencia de todas las demás photoReference.putFile(uriImagen).addOnSuccessListener(this, new OnSuccessListener<UploadTask.TaskSnapshot>() { @Override public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { String urlPhoto = taskSnapshot.getMetadata().getReference().getDownloadUrl().toString(); Log.v("Url de la foto", urlPhoto); Message m = new Message(tvName.getText().toString() + " te ha enviado una foto", urlPhoto, tvName.getText().toString(), "", "2", "00:00"); databaseReference.push().setValue(m); } }); } }
需要帮助..提前感谢
Task<Uri>
,请尝试一下。通过不建议使用此getMetadata().getReference().getDownloadUrl()
,建议您阅读此Upload-files firebasephotoReference.putFile(uriImagen).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Task<Uri> downloadUri = taskSnapshot.getStorage().getDownloadUrl();
if(downloadUri.isSuccessful()){
String urlPhoto = downloadUri.getResult().toString();
Log.v("Url de la foto", urlPhoto);
Message m = new Message(tvName.getText().toString() + " te ha enviado una foto", urlPhoto, tvName.getText().toString(), "", "2", "00:00");
databaseReference.push().setValue(m);
}}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
//Do whatever you want
}
});
尝试此代码:
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { Task<Uri> downloadUrl = taskSnapshot.getStorage().getDownloadUrl(); downloadUrl.addOnCompleteListener(new OnCompleteListener<Uri>() { @Override public void onComplete(@NonNull Task<Uri> task) { Log.v(TAG, "Media is uploaded"); String downloadURL = "https://" + task.getResult().getEncodedAuthority() + task.getResult().getEncodedPath() + "?alt=media&token=" + task.getResult().getQueryParameters("token").get(0); Log.v(TAG, "downloadURL: " + downloadURL); //save your downloadURL } }); }
Task<Uri>
,请尝试一下。通过不建议使用此getMetadata().getReference().getDownloadUrl()
,建议您阅读此Upload-files firebasepublic void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Task<Uri> downloadUrl = taskSnapshot.getStorage().getDownloadUrl();
downloadUrl.addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
Log.v(TAG, "Media is uploaded");
String downloadURL = "https://" + task.getResult().getEncodedAuthority()
+ task.getResult().getEncodedPath()
+ "?alt=media&token="
+ task.getResult().getQueryParameters("token").get(0);
Log.v(TAG, "downloadURL: " + downloadURL);
//save your downloadURL
}
});
}