2

I would like to check if android have a default excel reader if not show a download link for a reader . Is that possible ?

Rashad
  • 11,057
  • 4
  • 45
  • 73
  • i want to open a excel file so i need to check if thre is a default reader installed or not. – user3198245 Mar 03 '14 at 09:27
  • see here http://stackoverflow.com/questions/6621789/how-to-open-an-excel-file-in-android and here http://stackoverflow.com/questions/7170180/viewing-excel-files-in-my-android-app – rajshree Mar 03 '14 at 09:29
  • @rajshree OP asked how to detect if there is a reader installed. He didn't ask how to open an EXCEL file. The linked articles aren't helpful. – David Wasser Mar 03 '14 at 10:23

1 Answers1

3

You can use PackageManager.resolveActivity() to determine if there is something installed that can view the file. Here's an example:

PackageManager pm = getPackageManager();
File file = new File("filename"); // This is the file you want to show
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.fromFile(file));
// Determine if Android can resolve this implicit Intent
ResolveInfo info = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);

if (info != null) {
    // There is something installed that can VIEW this file)
} else {
    // Offer to download a viewer here
}
David Wasser
  • 93,459
  • 16
  • 209
  • 274