以下行存在错误。
找不到符号downloadUrl = task.getResult()。getDownloadUrl()。toString();
private void StoringImageToFirebaseStorage() {
Calendar calFordData = Calendar.getInstance();
SimpleDateFormat currentDate = new SimpleDateFormat("dd-MMMM-yyyy");
saveCurrentData = currentDate.format(calFordData.getTime());
Calendar calFordTime = Calendar.getInstance();
SimpleDateFormat currentTime = new SimpleDateFormat("HH:mm");
saveCurrentTime = currentTime.format(calFordData.getTime());
postRandomName = saveCurrentData + saveCurrentTime;
StorageReference filePath = PostsImagesRefrence.child("Post Images").child(ImageUri.getLastPathSegment()+ postRandomName + ".jpg");
filePath.putFile(ImageUri).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
@Override
public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
if (task.isSuccessful())
{
downloadUrl = task.getResult().getDownloadUrl().toString();
Toast.makeText(PostActivity.this, "Image uploaded successfully to storage", Toast.LENGTH_SHORT).show();
SavingPostInformationToDatabase();
}
else{
String message = task.getException().getMessage();
Toast.makeText(PostActivity.this, "Error Occurred", Toast.LENGTH_SHORT).show();
}
}
});
}
答案 0 :(得分:0)
将downloadUrl声明为字符串。
<body onload="PR.prettyPrint()">
<pre class="prettyprint linenums lang-html">
<script type="text/javascript">
// Say hello world until the user starts questioning
// the meaningfulness of their existence.
function helloWorld(world) {
for (var i = 42; --i >= 0;) {
alert('Hello ' + String(world));
}
}
</script>
<style>
p { color: pink }
b { color: blue }
u { color: "umber" }
</style>
</pre>
</body>
答案 1 :(得分:0)
您可以这样做:
filePath.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
downloadUrl = uri.toString();
SavingPostInformationToDatabase();
Toast.makeText(PostActivity.this, "Image uploaded successfully to storage", Toast.LENGTH_SHORT).show();
}
});