Android gets a intent for opening Word files

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.