recently in doing projects using WebView display, have to write a document need to open, find some information, research, get out!
Here's the main code:
param as the primary path to the document
public static Intent getwordfileintent (String param) {Intent Intent = null;try {Intent = new Intent ("Android.intent.action . VIEW "), Intent.addcategory (" Android.intent.category.DEFAULT "); Intent.addflags (Intent.flag_activity_new_task); Uri uri = uri.fromfile (new File (param)); Intent.setdataandtype (URI, "Application/msword");} catch (Exception e) {//TODO auto-generated catch Blocke.printstacktrace ();} return intent;}
After obtaining the intent, determine if it exists and prevent the crash:
/** * Determine if intent exists to prevent crashes * * @param context * @param intent * @return */private boolean isintentavailable (Context cont Ext, Intent Intent) {final Packagemanager Packagemanager = Context.getpackagemanager (); list<resolveinfo> list = packagemanager.queryintentactivities (intent,packagemanager.get_activities); return List.size () > 0;}
If List.size is less than O, indicate if Office is already installed:
Tools.showtoast (noticedetailactivity.this, "Please install Office");
Android gets a intent for opening Word files