0

please dont mark it as duplicate...i referring to this answer--> https://stackoverflow.com/a/54986577/12553303

nothing is happening on click of button...not getting download

 download.setOnClickListener {
                    if (ActivityCompat.checkSelfPermission(applicationContext,
                            Manifest.permission.READ_EXTERNAL_STORAGE) !== PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(
                            applicationContext,
                            Manifest.permission.WRITE_EXTERNAL_STORAGE) !== PackageManager.PERMISSION_GRANTED
                    ) {

                        // this will request for permission when user has not granted permission for the app
                        ActivityCompat.requestPermissions(this@Product_details,
                            arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE,
                                Manifest.permission.WRITE_EXTERNAL_STORAGE),
                            1)
                    } else {
                        //Download Script
                        val downloadManager: DownloadManager = getSystemService(DOWNLOAD_SERVICE) as DownloadManager
                        val uri = Uri.parse(product_images)
                        val request: DownloadManager.Request = DownloadManager.Request(uri)
                        request.setVisibleInDownloadsUi(true)
                        Toast.makeText(
                            applicationContext,
                           uri.toString(),
                            Toast.LENGTH_LONG
                        ).show()
                        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
                        request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,
                            uri.lastPathSegment)
                        downloadManager.enqueue(request)
                    }
                }

where product_image ==>val product_images:String =intent1.getStringExtra("image")

need help thanks

IRON MAN
  • 191
  • 3
  • 18

3 Answers3

1

Do away with that permission code.

Just start the downloadmanager .

For which you do not need any permission.

blackapps
  • 8,011
  • 2
  • 11
  • 25
  • hi can u help me out here -> https://stackoverflow.com/questions/76480901/facing-issue-while-making-dynamic-views-using-relative-layout – IRON MAN Jun 15 '23 at 11:22
0

Use Picasso or Glide library to download images from URL.

0

try this Picasso library

Tthis Link : Picasso

    Picasso.with(MainActivity::this)
       .load(imageUrl)
       .into(imageView, object: com.squareup.picasso.Callback {
                    override fun onSuccess() {
                        //set animations here

                    }

                    override fun onError(e: java.lang.Exception?) {
                        //do smth when there is picture loading error
                    }
                })
awshakam98
  • 495
  • 2
  • 5
  • 13