简体   繁体   English

我有一个关于 firebase 和 imageView 的问题

[英]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. 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我,我把所有的 url 对象都拿走了,但是在屏幕上 imageView 出现了最后添加的图像,我仍然可以从应用程序中添加照片,我尝试了 Picasso 和 Z86EE74BAFF479D85D18F2CDA9ZF,但它不起作用。

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然后go到你是firebase数据库规则你会发现如下规则

{
  /* 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.现在根据您的需要更改权限,例如,如果您设置为true ,那么任何拥有该链接的人都可以从任何平台看到图像,如果您设置request.auth.uid != null那么只有您应用的注册用户才能看到图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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