Search code examples
androidkotlinpicasso

How to save the content of an imageView to internal storage using picasso


Hello I am making an application and I am using the picasso library and I cannot find a way to save the image that appears in the imageView since the image is randomly generated by a link and I would like it to be saved when touching storage when touching a button

This is my method to make the images completely random

Any help is appreciated from the heart

override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        nextButton.setOnClickListener(object : View.OnClickListener {


            override fun onClick(v: View?) {

                imageRandomFun()
            }

        })
    }

private fun imageRandomFun() {
        val quest1 = "https://testrandom.com/" (Link no real)
        Picasso.get().load(quest1).memoryPolicy(MemoryPolicy.NO_CACHE).into(memeRandomView)
        Picasso.get().isLoggingEnabled = true
    }

Solution

  • You have to use a placeholder in your Picasso

    Picasso.with(context).load(imageUri).fit().centerCrop()
    .placeholder(R.drawable.user_placeholder)
    .error(R.drawable.user_placeholder_error)
    .into(imageView);