0

I'm trying to implement an OnClickListener that will launch a download from the Firebase Storage in PDF. But because it didn't work, I tried to implement it in image download instead. Is it necessary for a bitmap? I do not want the image to be loaded into an ImageView, but into the local storage of the android as an offline file.

The Login Authentication works for the Firebase but I'm not sure why the download is not working and if it is linked to the Network Request despite not enrolling onto the Beta of AppCheck. I referenced from the Firebase Storage documentation as well as various links but they were mostly in Java.

The error is: "W/NetworkRequest: No App Check token for request."

Separated for clarity purposes with a dummy gs link. Thanks!

Update: It seems to be a recent ongoing issue that others have also faced the same error message (No App Check Token) despite not enrolling into the Beta App Check for Firebase Storage. Is there any workaround for it so far as I do not want to implement App Check, thanks!

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = ActivityPayslipBinding.inflate(layoutInflater)
        setContentView(binding.root)

        // [START storage_field_initialization]
        storage = Firebase.storage
        // [END storage_field_initialization]

        /**dropdown for payslip month **/
        val month = resources.getStringArray(R.array.month)
        val monthArrayAdapter = ArrayAdapter(this, R.layout.dropdown_month, month)
        binding.autoCompleteMonth.setAdapter(monthArrayAdapter)

        /** dropdown for payslip year **/
        val year = resources.getStringArray(R.array.year)
        val yearArrayAdapter = ArrayAdapter(this, R.layout.dropdown_year, year)
        binding.autoCompleteYear.setAdapter(yearArrayAdapter)

        /** onclick listener to launch download **/
        binding.monthlyPayslipButton.setOnClickListener {
            includesForDownloadFiles()
        }

    /** download function **/
    private fun includesForDownloadFiles() {
        // Creating a storage reference from our app
        val storageRef = storage.reference

    // Creating a reference with an initial file path and name
        val pathReference = storageRef.child("payslips/sample_0322.png")

    // Creating a reference to a file from a Google Cloud Storage URI
        val gsReference = storage.getReferenceFromUrl("gs://sample-5541c.appspot.com/payslips/sample_0322.png")

        var payslipRef = storageRef.child("payslips/sample_0322.png"")

        val localFile = File.createTempFile("images", "png")

        payslipRef.getFile(localFile).addOnSuccessListener {
            // Local temp file has been created
            Toast.makeText(this , "successfully downloaded" , Toast.LENGTH_SHORT).show()
        }.addOnFailureListener {
            // Handle any errors
            Toast.makeText(this , "failed to download" , Toast.LENGTH_SHORT).show()
        }
    }
Melona
  • 1
  • 1
  • Tell us what is wrong with shared code. Do you have any errors? – Alex Mamo Mar 21 '22 at 10:15
  • @AlexMamo hello, the error message is: "W/NetworkRequest: No App Check token for request." Apart from that, there's actually no other error reflected on the Runtime console – Melona Mar 21 '22 at 11:13

0 Answers0