从V5.1版本开始,WPS移动版本提供了额外的功能,可以供第三方程序通过集成的方式调用“WPS移动版”打开文件,打开的文件保存和关闭时第三方也可接收到广播通知。
通过此接口,开发者可以实现通过某程序打开office文档时,直接进入阅读模式,同时退出后,会将阅读进度返回给该程序,这样下次再阅读时可以从上次阅读的位置继续阅读。以下是具体接口使用说明和注意事项。
使用Intent打开WPS如下:
booleanopenFile(String path)
{
Intent intent= newIntent();
Bundle bundle= newBundle();
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= newFile(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”目前支持以下几种方式:
【保存文件】
【打开文件】
【关闭文件】