'Download manager uri is returing a number instead of the file location in android

I have a broadcast receiver for android that is supposed to open an intent to a pdf i am downloading but when it opens up the intent it opens a blank pdf, when i debug it it's giving me content://downloads/all_downloads/431 as the location instead of the file, the 431 is the dowload number and increases each time i download the pdf, my receiver looks like this.

    override fun onReceive(context: Context?, intent: Intent) {
    val action = intent.action
    if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {

        
        val manager = context!!.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
        val completeDownloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1)
        var uri: Uri? = manager.getUriForDownloadedFile(completeDownloadId)

        Log.d("BROADCASTEND", uri.toString())
        val intent = Intent(Intent.ACTION_VIEW)
        intent.data = uri
        MApplication.currentActivity.startActivity(intent)

    }
}

does anyone know why it opens a blank pdf and references the number instead of the file? i can see that it is downloading the pdf.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source