Open the app on your phone with the ability to read word,excle or PDF via intent, and let that file open. This gives the word,excle open
Openword class
Package Com.example.tomorrow.mobileoa.utils;import Android.content.context;import Android.content.intent;import Android.content.pm.packagemanager;import Android.content.pm.resolveinfo;import Android.net.Uri;import Java.io.file;import java.util.list;/** * Created by He on 11/10 2015.
* Wang */public class Openword {//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) {e.printstacktrace (); } return intent; } public static Intent getexcelfileintent (File param) {Intent Intent = new Intent ("Android.intent.action.VIE W "); Intent.addcategory ("Android.intent.category.DEFAULT"); Intent.addflags (Intent.flag_activity_new_task); Uri uri = uri.fromfile (param); Intent.setdataandtype (URI, "application/vnd.ms-excel"); return intent; }/** * Determine if intent exists to prevent crashes * @param context * @param intent * @return */public static Boolean I SintentavaIlable (context context, Intent Intent) {final Packagemanager Packagemanager = Context.getpackagemanager (); list<resolveinfo> list = Packagemanager.queryintentactivities (Intent, packagemanager.get_activities) ; return list.size () > 0; }}
To bind an event to a button
Bt_download_look.setonclicklistener (New View.onclicklistener () { @Override public void OnClick (View v) { String name = Files.get (position). GetName (); FileUtils FileUtils = new FileUtils (); String path = Fileutils.getsdpath () + "mobileoa/" + name; Intent Intent = openword.getwordfileintent (path); Boolean flag = openword.isintentavailable (context, intent); if (!flag) { Toast.maketext (context, "Please install offer", Toast.length_short). Show (); } else { Context.startactivity (intent);}} );
Android gets a intent for opening Word files