从Firebase Storage下载图像知道链接

问题描述 投票:0回答:1

[您好,由于Android编程中的新功能,我需要很大的帮助来解决此问题,然后我创建了一个图像应用,图像由我上传到Firebase Storage,因此我可以随时访问链接和令牌,因此,当用户选择要下载的图像时,现在我已经分割了我的应用程序,因此我创建了与图像一样多的片段,并且与图像相关的片段中包含了下载按钮,现在我向您展示如何>

import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

    public class fragment_1 extends Fragment {
    Button bntDwn_1;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_1, container, false);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        bntDwn_1 = (Button) getActivity().findViewById(R.id.dwn_1);
        bntDwn_1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //here I would like to insert the function to download the image directly

            }
        });
    }
}

现在向您展示片段的布局

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".fragment_1">

    <ImageView
        android:id="@+id/sfondo_1"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:contentDescription="@string/sfondo_1"
        android:src="@drawable/forpaper_1"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0" />

    <Button
        android:id="@+id/dwn_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="4dp"
        android:text="@string/scarica"
        app:layout_constraintBottom_toBottomOf="@+id/sfondo_1"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="1.0" />

</androidx.constraintlayout.widget.ConstraintLayout>

现在向您展示MainActivity

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;
import java.util.Random;

public class MainActivity extends AppCompatActivity {

    private StorageReference mStorageRef;
    public Random mRandom;
    public TextView mCounterCrd;

    int StringCrd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //Inizializzazione Archiviazione Cloud
        mStorageRef = FirebaseStorage.getInstance().getReference();


        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction tx =  fm.beginTransaction();
        fragment_1 fragmentview = new fragment_1();
        tx.replace(R.id.frame_place, fragmentview);
        tx.commit();
       }
    }

现在,我想问一个函数来下载已经知道链接的文件,然后在每个引用按钮的onClick函数下针对每个图像手动插入该文件,希望您可以提供许多有用的提示或必要的更改来帮助我,感谢所有人。

您好,因为Android编程中的新功能,所以我需要很大的帮助来解决此问题,然后我创建了一个图像应用程序,图像由我上传到Firebase Storage上,因此我可以访问...

android firebase storage
1个回答
0
投票
在您的按钮单击中调用此函数并传递imageUrl
© www.soinside.com 2019 - 2024. All rights reserved.