原文连接:http://bbs.wps.cn/thread-22349340-1-1.htmlphp
从V5.1版本开始,WPS移动版本提供了额外的功能,能够供第三方程序经过集成的方式调用“WPS移动版”打开文件,打开的文件保存和关闭时第三方也可接收到广播通知。 经过此接口,开发者能够实现经过某程序打开office文档时,直接进入阅读模式,同时退出后,会将阅读进度返回给该程序,这样下次再阅读时能够从上次阅读的位置继续阅读。如下是具体接口使用说明和注意事项。 【打开文件】 调用startActivity 打开, 具体以下: 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; } 其中className为“cn.wps.moffice.documentmanager.PreStartActivity2”,packageName根据版本分别为: ”cn.wps.moffice_eng”(普通版),”cn.wps.moffice_eng”(英文版)。要打开的文件经过Uri传入,其它要传入参数详见下表: “OpenMode”目前支持如下几种方式:
【保存文件】
文件保存时会发送一个"cn.wps.moffice.file.save"的广播,第三方程序根据须要接听广播。广播含有文件的路径信息,打开文件时传递的包名等,使用时酌情解析,具体见下表:
【关闭文件】 文件关闭时会发送一个"cn.wps.moffice.file.close"的广播,第三方程序根据须要接听广播。广播含有文件的路径信息,打开文件时传递的包名等,使用时酌情解析,具体见下表: 具体能够参考附件的例子testThirdInterface |
支持方式.JPG html
保存文件.JPG android
open file.JPG post
关闭文件.JPG spa
45.21 KB, 下载次数: 2296blog