1 回答
TA贡献1828条经验 获得超3个赞
使用以下代码获取下载 uri 并存储在 Firestore 中。把它放在onSucess里面
uploadTask.getDownloadUrl().addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
String downloadThumbUri = task.getResult().toString();
Map<String,Object> postMap = new HashMap<>();
postMap.put("image url",downloadUri);
postMap.put("thumb",downloadThumbUri);
postMap.put("desc",desc);
postMap.put("user_id",current_user_id);
postMap.put("timestamp",FieldValue.serverTimestamp());
firebaseFirestore.collection("Posts").add(postMap).addOnCompleteListener(new OnCompleteListener<DocumentReference>() {
@Override
public void onComplete(@NonNull Task<DocumentReference> task) {
if(task.isSuccessful()){
newPostProgress.setVisibility(View.INVISIBLE);
Toast.makeText(NewPostActivity.this,"Post was added ",Toast.LENGTH_LONG).show();
Intent mainIntent = new Intent(NewPostActivity.this,MainActivity.class);
startActivity(mainIntent);
finish();
}
});
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
progressBar.setVisibility(View.GONE);
Toast.makeText(ProfileActivity.this, "aaa "+e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
添加回答
举报