简体   繁体   中英

I have a question about firebase and imageView

I have such a problem with objects in which there is an Url image, and I need to take these objects from firebase realtimeDatabase and take Url from them and insert their method that creates the imageView and adds with the image to the linerleaut, everything works for me, I take everything all url objects I take but on the screen the imageView appears with the last added image, de still I can add a photo from the application,i tried Picasso and Bitmap but it doesn't work.

enter code here
databaseReference.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot snapshot) {

                linearLayoutShirt.removeAllViews();
                linearLayoutPant.removeAllViews();
                for (DataSnapshot postSnapshot : snapshot.getChildren()) {
                    Image object = postSnapshot.getValue(Image.class);
                 linearLayoutShirt.addView(test(dress, 300, 300));
                           
                    

                }
            }


            @Override
            public void onCancelled(DatabaseError databaseError) {
                Toast.makeText(MyActivity.this, "The read failed: " + databaseError.getMessage(), Toast.LENGTH_LONG).show();


            }
        });




public LinearLayout test(final Image image, int weight, int height) {
        LinearLayout infoView = new LinearLayout(MyActivity.this);
        LinearLayout.LayoutParams infoViewParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        infoView.setPadding(30, 30, 30, 30);

        infoView.setOrientation(LinearLayout.VERTICAL);
        infoView.setLayoutParams(infoViewParams);


        ImageView infoImageView = new ImageView(MyActivity.this);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(weight, height);
        infoImageView.setLayoutParams(params);

        new getImageFromUrl(infoImageView).execute(image.getImage());


        /*//Picasso.get().load(image.getImage()).into(infoImageView);

        try {
            Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), Uri.parse(dress.getImage()));
            infoImageView.setImageBitmap(bitmap);
        } catch (IOException e) {
            e.printStackTrace();
        }*/

        infoView.addView(infoImageView);



        return infoView;
    }

在此处输入图像描述

As you said in your comment you're getting the following

{ error: { code: 403, message: "Permission denied. Could not perform this operation" } }

Then go to you're firebase database rules you'll find the following rules

{
  /* Visit https://firebase.google.com/docs/database/security to learn more about security rules. */
  "rules": {
    ".read": false,
    ".write": false //It is advised to set this rule as request.auth.uid != null to ensure no one will access to modify your data
  }
}

Now change the permission's according to your need like if you set true then anyone with the link can see the image from any platform and if you set request.auth.uid != null then only a registered user of your app can see the image.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM