【发布时间】:2021-12-12 01:27:45
【问题描述】:
我知道有几种方法可以替换 getDownloadUrl(),但它对我不起作用。 如果有人知道好的方法请帮助我
所以我正在尝试上传一些带有照片的帖子。除了我上传的图片外,其他的东西都会出现。我认为 getDownloadUrl() 是问题所在。
public void onClick(View v) {
if (v.getId() == R.id.addphoto_btn_upload && photoUrl != null) {
Log.d("AddPhotoActivity", " upload button clicked");
File myFile = new File(photoUrl);
Uri contentUri = Uri.fromFile(myFile);
StorageReference storageReference = firebaseStorage.getReferenceFromUrl("gs://mystagram.appspot.com/").child("images").child(contentUri.getLastPathSegment());
UploadTask uploadTask = storageReference.putFile(contentUri);
uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(AddPhotoActivity.this, getString(R.string.upload_success), Toast.LENGTH_SHORT).show();
Task<Uri> uri = taskSnapshot.getStorage().getDownloadUrl();
DatabaseReference images = firebaseDatabase.getReference().child("images").push();
//Time
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
ContentDTO contentDTO = new ContentDTO();
contentDTO.imageUrl = uri.toString();
contentDTO.explain = explain_editText.getText().toString();
contentDTO.userId = firebaseAuth.getCurrentUser().getEmail();
contentDTO.timeStamp = Long.valueOf(simpleDateFormat.format(date));
images.setValue(contentDTO);
AddPhotoActivity.this.finish();
}
});
我该如何更改?
【问题讨论】:
标签: java android firebase android-studio deprecated