package com.burhanstore.neonbubblequest.Utils import android.app.DownloadManager import android.content.Context import android.net.Uri import android.os.Environment import android.widget.Toast object AppWork { fun downloadImage(context: Context, url: String) { try { val fileName = "image_${System.currentTimeMillis()}.jpg" val request = DownloadManager.Request(Uri.parse(url)) .setTitle("Downloading image") .setDescription("Saving image to Downloads") .setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) .setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName) .setAllowedOverMetered(true) .setAllowedOverRoaming(true) val manager = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager manager.enqueue(request) Toast.makeText(context, "Downloading started...", Toast.LENGTH_SHORT).show() } catch (e: Exception) { Toast.makeText(context, "Error: ${e.message}", Toast.LENGTH_SHORT).show() } } }