How to add an image stored in firebase Torage to imageView inside an infowindow of a Marketer?

Asked

Viewed 709 times

0

I need to download a firebase image and display it in a custom infowindow on a map.

public class MapaFocosActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener, GoogleMap.OnInfoWindowClickListener, OnMapReadyCallback , GoogleMap.InfoWindowAdapter{

    private GoogleMap mMap;
    private FirebaseStorage storage;
    private StorageReference storageRef;
    private ImageView img;
    private View v;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        .
        .
        .

        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.fragment_mapa);
        mapFragment.getMapAsync(this);

        storage = FirebaseStorage.getInstance();
        storageRef = storage.getReferenceFromUrl("gs://...com");

    }

    .
    .
    .

    @Override
    public void onInfoWindowClick(Marker marker) {

    }

    @Override
    public View getInfoWindow(Marker marker) {
        return null;
    }

    @Override
    public View getInfoContents(Marker marker) {
        StorageReference imageRef = storageRef.child(marker.getTag().toString()+".jpg");
        v = getLayoutInflater().inflate(R.layout.marker_window_info, null);
        img = (ImageView) v.findViewById(R.id.img_foco_info);
        Glide.with(MapaFocosActivity.this)
                .using(new FirebaseImageLoader())
                .load(imageRef)
                .into(img);
        File localFile = null;
        Bitmap bitmap=null;
        try {
            localFile = File.createTempFile("images", "jpg");
            final File finalLocalFile = localFile;
            imageRef.getFile(localFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
                @Override
                public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
                    // Local temp file has been created


                }
            }).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception exception) {
                    // Handle any errors

                }
            });
            bitmap= BitmapFactory.decodeFile(finalLocalFile.getAbsolutePath());
        } catch (IOException e) {
            e.printStackTrace();
            Log.e("FOTO", "o Arquivo nao foi criado!");
        }

        img.setImageBitmap(bitmap);
        TextView txt_desc = (TextView) v.findViewById(R.id.txt_desc_foco_info);
        txt_desc.setText(marker.getTag()+"\n"+marker.getPosition());
        return v;
    }
}

I tested and the image does not appear. How can I make it appear in the imageView?

1 answer

0


You cannot pass the imageReference directly to the Glide as in the excerpt

StorageReference imageRef = storageRef.child(marker.getTag().toString()+".jpg");
Glide.with(MapaFocosActivity.this)
                .using(new FirebaseImageLoader())
                .load(imageRef) // <--- Aqui não pode ser assim.
                .into(img);

, you have to pass the Redirect download URL directly.

I don’t use the Loader, I always take the Download URL from the file and upload. But one thing I do I leave the reading permission enabled if there is no time it stops to open the image.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.