從V5.1版本開始,WPS移動版本提供了額外的功能,可以供第三方程序通過集成的方式調用“WPS移動版”打開文件,打開的文件保存和關閉時第三方也可接收到廣播通知。
通過此接口,開發者可以實現通過某程序打開office文檔時,直接進入閱讀模式,同時退出后,會將閱讀進度返回給該程序,這樣下次再閱讀時可以從上次閱讀的位置繼續閱讀。以下是具體接口使用說明和注意事項。
使用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; }
【保存文件】
文件保存時會發送一個"cn.wps.moffice.file.save"的廣播,第三方程序根據需要接聽廣播。廣播含有文件的路徑信息,打開文件時傳遞的包名等,使用時酌情解析,具體見下表:
【關閉文件】
文件關閉時會發送一個"cn.wps.moffice.file.close"的廣播,第三方程序根據需要接聽廣播。廣播含有文件的路徑信息,打開文件時傳遞的包名等,使用時酌情解析,具體見下表:
【參數說明】
其中className為“cn.wps.moffice.documentmanager.PreStartActivity2”,packageName根據版本分別為: ”cn.wps.moffice_eng”(普通版),”cn.wps.moffice_eng”(英文版)。要打開的文件通過Uri傳入,其它要傳入參數詳見下表:
“OpenMode”目前支持以下幾種方式:
【保存文件】
【打開文件】
【關閉文件】
原文地址:http://bbs.wps.cn/thread-22349340-1-1.html