0

i am trying to upload a pdf file by browsing and choosing a pdf from the android phone, but when I check the length of the file after choosing a pdf file it is always 0

//Select a PDF file containing the utility bill
private fun openPdfFileBrowser() {
        val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
        addCategory(Intent.CATEGORY_OPENABLE)
        //Only allow the user to select 'PDF' files within their chosen file explorer application
        type = "application/pdf"
    }
    startActivityForResult(intent, FILE_BROWSER_REQUEST_CODE)
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    if (resultCode == Activity.RESULT_OK && requestCode == FILE_BROWSER_REQUEST_CODE) {
        val uri: Uri? = data!!.getData() // uri: content://com.android.providers.media.documents/document/document%3A28437

        if (uri != null) {

            val newPath = uri.path // = /document/document:28437
            val fileTest = File(uri.path)
            val fileLength = file.length() // is 0
            val fileLengthx = Integer.parseInt((file.length()/1024).toString()) // is 0

            //startUtilityUploadProcess(newPath!!, "utility_bill.pdf", "PDF")
        }
    }
}

could you please suggest what a I doing wrong here please

thanks a lot in advance R

BRDroid
  • 3,190
  • 6
  • 43
  • 100

0 Answers0