簡體   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我,我把所有的 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;
    }

在此處輸入圖像描述

正如您在評論中所說,您將獲得以下信息

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

然后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
  }
}

現在根據您的需要更改權限,例如,如果您設置為true ,那么任何擁有該鏈接的人都可以從任何平台看到圖像,如果您設置request.auth.uid != null那么只有您應用的注冊用戶才能看到圖像。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM