zoukankan      html  css  js  c++  java
  • Android 实现 调用 WPS Office手机版接口

    从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

  • 相关阅读:
    HDU 5213 分块 容斥
    HDU 2298 三分
    HDU 5144 三分
    HDU 5145 分块 莫队
    HDU 3938 并查集
    HDU 3926 并查集 图同构简单判断 STL
    POJ 2431 优先队列
    HDU 1811 拓扑排序 并查集
    HDU 2685 GCD推导
    HDU 4496 并查集 逆向思维
  • 原文地址:https://www.cnblogs.com/ywtk/p/4031689.html
Copyright © 2011-2022 走看看