Unable to Show Image In ImageView From Firebase Storage

前端 未结 2 746
我在风中等你
我在风中等你 2021-01-07 04:08

I have an app which allows the users to upload the images to a Firebase bucket,then I get the download URL of the image file and add it to a firebase database.The URL is in

相关标签:
2条回答
  • 2021-01-07 04:47

    With Picasso you can load a simple image using:

    Picasso.with(Activity.this).load("your url image").into(imageView);
    

    Need add in Glade:

     compile 'com.squareup.picasso:picasso:2.5.2'
    
    0 讨论(0)
  • 2021-01-07 04:53

    To get Images form Camera

                        Intent i = new Intent(Intent.ACTION_PICK,MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                        startActivityForResult(i, 3);
    

    To get the filepath of an Image

     @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == PICK_FILE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
    
          String  path=String.valueOf(data.getData());
          file = Uri.fromFile(new File(path));
    

    Create the file metadata

      metadata = new StorageMetadata.Builder()
        .setContentType("image/jpeg")
        .build();
    

    Upload file and metadata to the path 'images/avator.jpg'

      uploadTask = storageRef.child("images/"+file.getLastPathSegment()).putFile(file, metadata);
    

    Listen for state changes, errors, and completion of the upload.

      uploadTask.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
    @Override
    public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
        double progress = (100.0 * taskSnapshot.getBytesTransferred()) / taskSnapshot.getTotalByteCount();
        System.out.println("Upload is " + progress + "% done");
    }
    }).addOnPausedListener(new OnPausedListener<UploadTask.TaskSnapshot>() {
    @Override
    public void onPaused(UploadTask.TaskSnapshot taskSnapshot) {
        System.out.println("Upload is paused");
    }
    }).addOnFailureListener(new OnFailureListener() {
     @Override
    public void onFailure(@NonNull Exception exception) {
        // Handle unsuccessful uploads
    }
    }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
    @Override
    public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
        // Handle successful uploads on complete
        Uri downloadUrl = taskSnapshot.getMetadata().getDownloadUrl();
    
    }
    

    });

    To load the Image using Glide Library

      Glide.with(getActivity())
    .load(new File(downloadUrl)) // Uri of the picture
    .into(Imageview);
    
    0 讨论(0)
提交回复
热议问题