Reputation: 25
I would like to check if android
have a default excel reader if not show a download link for a reader . Is that possible ?
Upvotes: 2
Views: 1289
Reputation: 95618
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
}
Upvotes: 3