I was trying to open files that are placed in a folder. The idea is to provide maximum type of office files + pdf that a downloaded app can open. So i downloaded 14 different samples of file type like .docx, .ppt, .pdf etc. I have WPS office as application to run these. But the problem is that when i use the below code then directly file is opened in WPS office application. And if i change to target.setDataAndType(Uri.fromFile(open), "application/pdf");
then it show adobe reader and WPS office as option. Is there any way that i get best possible option to open the file without specifying specifically /pdf or /msword? such that i get possible app list according to input type.
Intent target = new Intent(Intent.ACTION_VIEW);
target.setDataAndType(Uri.fromFile(open), "application/msword");
target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
Intent intent = Intent.createChooser(target, "Open File");
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
// Instruct the user to install a PDF reader here, or
// something
Toast.makeText(
getApplicationContext(),
"Please install proper document reader in your device to open this file",
Toast.LENGTH_SHORT).show();
}
0 comments:
Post a Comment