0

I am working on an application to read excel file (xlsx) file data. I was using custom file picker to select the file in android 10 and below, But in Andrid 11 it doesnt show the xlsx files.

So i made a change in my code for Android 11.

//to launch file picker
getContent.launch("*/*")

//to read selected file
val getContent = registerForActivityResult(ActivityResultContracts.GetContent()) { uri: Uri? ->
        readExcelData(uri!!.path!!)
}

the above code "uri!!.path!!" gives exception

/document/primary:Android/OldFileWithNewRecords.xlsxException:
E/ExcelActivity: FileNotFoundException/document/primary:Android/OldFileWithNewRecords.xlsx: open failed: ENOENT (No such file or directory)

Is there any way i can get the exact path of the file selected?

I tried SimpleStorage and this solution but was not able to succeed.

KhanStan99
  • 414
  • 8
  • 20
  • "Is there any way i can get the exact path of the file selected?" -- no. First, the user might not have selected a file on the filesystem. Second, even if they did, you probably do not have access to that file on the filesystem. – CommonsWare Feb 09 '22 at 12:50
  • For no file selected, i can apply the null check, but how can i get the file path in selected scenario? – KhanStan99 Feb 10 '22 at 05:00

0 Answers0