I'm trying to open an XLSX
file within my Android App.
I'm aware that the Intent
type I have to fire is application/excel
, but despite I've installed Google Sheets
, my code says that no application can open my excel file.
This is the code I use to fire the Intent
:
private void openXLS(){
File xls = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS), "prova.xlsx");
Uri path = Uri.fromFile(xls);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/excel");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
context.startActivity(intent);
} catch (ActivityNotFoundException e) {
Toast.makeText(context, "No Application available to view XLS", Toast.LENGTH_SHORT).show();
}
}
Note: prova.xlsx
exists, and I'm able to reach it and open it.