Android 实现 调用 WPS Office手机版接口
從V5.1版本開始,WPS移動版本提供了額外的功能,可以供第三方程序通過集成的方式調(diào)用“WPS移動版”打開文件,打開的文件保存和關(guān)閉時第三方也可接收到廣播通知。
通過此接口,開發(fā)者可以實現(xiàn)通過某程序打開office文檔時,直接進(jìn)入閱讀模式,同時退出后,會將閱讀進(jìn)度返回給該程序,這樣下次再閱讀時可以從上次閱讀的位置繼續(xù)閱讀。以下是具體接口使用說明和注意事項。
?
使用Intent打開WPS如下:
boolean openFile(String path){Intent intent = new Intent();Bundle bundle = new Bundle();bundle.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;}?
?
【保存文件】 文件保存時會發(fā)送一個"cn.wps.moffice.file.save"的廣播,第三方程序根據(jù)需要接聽廣播。廣播含有文件的路徑信息,打開文件時傳遞的包名等,使用時酌情解析,具體見下表:
【關(guān)閉文件】
? ?? ? 文件關(guān)閉時會發(fā)送一個"cn.wps.moffice.file.close"的廣播,第三方程序根據(jù)需要接聽廣播。廣播含有文件的路徑信息,打開文件時傳遞的包名等,使用時酌情解析,具體見下表:
?
【參數(shù)說明】
其中className為“cn.wps.moffice.documentmanager.PreStartActivity2”,packageName根據(jù)版本分別為: ”cn.wps.moffice_eng”(普通版),”cn.wps.moffice_eng”(英文版)。要打開的文件通過Uri傳入,其它要傳入?yún)?shù)詳見下表:
?
“OpenMode”目前支持以下幾種方式:
?
?
?
【保存文件】?
【打開文件】
?
【關(guān)閉文件】
?
原文地址:http://bbs.wps.cn/thread-22349340-1-1.html
?
轉(zhuǎn)載于:https://www.cnblogs.com/ywtk/p/4031689.html
總結(jié)
以上是生活随笔為你收集整理的Android 实现 调用 WPS Office手机版接口的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 成外培训
- 下一篇: 灾难恢复演练成功的8大步骤