How android calls WPS to display work files
The following is a sample code for opening a document using the WPS Chinese edition (the package names of different WPS languages are slightly different. Please note the red part ):
<Open a file>
Open startActivity by calling: boolean openFile (String path) {Intent intent = new Intent (); Bundle bundle = new Bundle ();
// Set requirements based on different situations
// The following budle is the bundle that controls the scenario. putString (OPEN_MODE, READ_ONLY); bundle. putBoolean (SEND_CLOSE_BROAD, true); bundle. putString (THIRD_PACKAGE, selfPackageName); bundle. putBoolean (CLEAR_BUFFER, true); bundle. putBoolean (CLEAR_TRACE, true); // bundle. putBoolean (CLEAR_FILE, true); intent. addFlags (Intent. FLAG_ACTIVITY_NEW_TASK); intent. setAction (android. content. intent. ACTION_VIEW); intent. setClassName (packageName, ClassName); File file = new File (path); if (file = null |! File. exists () {return false;} Uri uri = Uri. fromFile (file); intent. setData (uri); intent. putExtras (bundle); try {startActivity (intent);} catch (ActivityNotFoundException e) {e. printStackTrace (); return false;} return true ;}
In this example, classnameis “cn.wps.moffice.doc umentmanager. PreStartActivity2 ", and packageName is" cn. wps. moffice_eng "(Basic edition) and" cn. wps. moffice_eng "(English version ). The file to be opened is passed in through Uri. For other parameters to be passed in, see the following table:
[Save file] a broadcast of cn. wps. moffice. file. save is sent when the file is saved. A third-party program receives the broadcast as needed. Broadcast the path information of the file, the package name that is passed when the file is opened, and parse it as needed. The details are shown in the following table:
Close a file]
When the file is closed, a broadcast of cn. wps. moffice. file. close will be sent, and a third-party program will answer the broadcast as needed. Broadcast the path information of the file, the package name that is passed when the file is opened, and parse it as needed. The details are shown in the following table:
Supported Methods
Close file
Save files
Open a file