i want open common file such doc/xls/ppt/pdf/dwg,but can't find view can this,common view open 1 or 2 type file.what third can me this. android :)
to open doc file can use follow
public class mainactivity extends activity { @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); button button = (button) findviewbyid(r.id.bpressme); button.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { file file = new file(environment.getexternalstoragedirectory(), "help desk voice flow.doc"); try { if (file.exists()) { uri path = uri.fromfile(file); intent objintent = new intent(intent.action_view); // replace "application/msword" // "application/vnd.openxmlformats-officedocument.wordprocessingml.document" // docx files // objintent.setdataandtype(path,"application/msword"); objintent.setflags(intent.flag_activity_clear_top); startactivity(objintent); } else { toast.maketext(mainactivity.this, "file notfound", toast.length_short).show(); } } catch (activitynotfoundexception e) { toast.maketext(mainactivity.this, "no viewer application found", toast.length_short) .show(); } catch (exception e) { e.printstacktrace(); } } }); }
Comments
Post a Comment