如何使用Android上传Firebase的多个图像

时间:2019-01-12 19:55:31

标签: android firebase firebase-realtime-database android-image

我正在创建一个应用程序,可以在其中上传两张图片以及一些信息,但是我无法将两张图片上传到Firebase实时数据库中。下面是我的代码,请帮忙。

public abstract class BaseCreatePostActivity<V extends BaseCreatePostView, P extends BaseCreatePostPresenter<V>>
    extends PickImageActivity<V, P> implements BaseCreatePostView {

protected ImageView imageView;
protected ImageView imageView2;
protected ProgressBar progressBar;
protected EditText titleEditText;
protected EditText descriptionEditText;



@SuppressLint("ClickableViewAccessibility")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.base_create_post_activity);
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    titleEditText = findViewById(R.id.titleEditText);
    descriptionEditText = findViewById(R.id.descriptionEditText);
    aliasEditText = findViewById(R.id.aliasEditText);


    progressBar = findViewById(R.id.progressBar);

    imageView = findViewById(R.id.imageView);
    imageView2 = findViewById(R.id.imageView2);

    imageView.setOnClickListener(v -> onSelectImageClick(v));

    imageView2.setOnClickListener(k -> onSelectImageClick(k));

    titleEditText.setOnTouchListener((v, event) -> {
        if (titleEditText.hasFocus() && titleEditText.getError() != null) {
            titleEditText.setError(null);
            return true;
        }

        return false;
    });
}

@Override
protected ProgressBar getProgressView() {
    return progressBar;
}

@Override
protected ImageView getImageView() {
    return imageView;
}



@Override
protected void onImagePikedAction() {
    loadImageToImageView(imageUri);
}

@Override
public void setDescriptionError(String error) {
    descriptionEditText.setError(error);
    descriptionEditText.requestFocus();
}

@Override
public void setTitleError(String error) {
    titleEditText.setError(error);
    titleEditText.requestFocus();
}

@Override
public void setAliasError(String error) {
    aliasEditText.setError(error);
    aliasEditText.requestFocus();
}


@Override
public String getTitleText() {
    return titleEditText.getText().toString();
}

@Override
public String getDescriptionText() {
    return descriptionEditText.getText().toString();
}



@Override
public void requestImageViewFocus() {
    imageView.requestFocus();
}

@Override
public void onPostSavedSuccess() {
    setResult(RESULT_OK);
    this.finish();
}

@Override
public Uri getImageUri() {
    return imageUri;
}

我为实现这一目标付出了很多努力,但我没有成功。任何小小的帮助将不胜感激。谢谢 我为实现这一目标付出了很多努力,但我没有成功。任何小小的帮助将不胜感激。谢谢

1 个答案:

答案 0 :(得分:0)

请阅读文档

https://firebase.google.com/docs/storage/android/upload-files

相信我,这很简单!