I want to fetch a file from the internal device storage in my app. The code for browsing through the internal storage is as follows
public void select(){
Intent intent = new Intent();
//intent.setType("file/*");
intent.setType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent,86);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==86 && resultCode==RESULT_OK && data!=null){
a=data.getData().getPath();
//Log.e("uri",a);
path.setText("File selected: "+data.getData().getLastPathSegment());
}
else{
Toast.makeText(Template.this,"Please select a file",Toast.LENGTH_SHORT).show();
}
}
I am passing a as an input to the following function to fetch the data from the excel file
public void convert(String uri){
Log.e("Tag","uri");
reference= FirebaseDatabase.getInstance().getReference();
File file = new File(uri);
try {
Log.e("Try","Try");
Workbook wb= Workbook.getWorkbook(file);
Sheet s = wb.getSheet(0);
int row=s.getRows();
int col=s.getColumns();
//for (int i=1;i<row;i++){
for(int j=0;j<col;j++) {
Log.e("Tag",s.getCell(j,0).getContents());
}
//}
} catch (IOException e) {
Log.e("msg",e.getMessage());
e.printStackTrace();
} catch (BiffException e) {
Log.e("msg",e.getMessage());
e.printStackTrace();
}
}
This is the output I get:
/document/primary:Android/data/com.example.societyapp/files/Download/Maintenance Details.xlsx: open failed: ENOENT (No such file or directory)