引用:http://bbs.wps.cn/thread-22327642-1-1.html


以下是指定使用WPS中文版打开文档的代码示例(WPS不同语言版的包名略有不同,请注意红色标记部分哦):


<打开文件>

  调用startActivity 打开, 具体如下:  boolean openFile(String path)     {             Intent intent = new Intent();                 Bundle bundle = new Bundle();
//根据不同情况设置要求
//下面的budle都是控制情景的                 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传入,其它要传入参数详见下表:


【保存文件】        文件保存时会发送一个"cn.wps.moffice.file.save"的广播,第三方程序根据需要接听广播。广播含有文件的路径信息,打开文件时传递的包名等,使用时酌情解析,具体见下表:

【关闭文件】
       文件关闭时会发送一个"cn.wps.moffice.file.close"的广播,第三方程序根据需要接听广播。广播含有文件的路径信息,打开文件时传递的包名等,使用时酌情解析,具体见下表:
 

 支持方式


    关闭文件

    

  保存文件 



  打开文件






给大家提供一个Demo下载地址: Android_WPS.rar




更多相关文章

  1. 一款常用的 Squid 日志分析工具
  2. GitHub 标星 8K+!一款开源替代 ls 的工具你值得拥有!
  3. RHEL 6 下 DHCP+TFTP+FTP+PXE+Kickstart 实现无人值守安装
  4. Linux 环境下实战 Rsync 备份工具及配置 rsync+inotify 实时同步
  5. Android(安卓)Mediascanner实现机制
  6. Android(安卓)Logcat 报错:Could not create the view: For input
  7. Android中使用Sonar进行代码质量分析
  8. Android(安卓)图片文件夹区别
  9. Android(安卓)SDK: adb 常用命令的使用(无线连接、端口转发、文件

随机推荐

  1. android ndk与sdk
  2. Android中PackageManager学习笔记(3)-Pac
  3. 关于Android(安卓)Studio关闭模拟器死机
  4. view随着键盘移动
  5. Android(安卓)Google 地图学习
  6. 2021-01-12 Android对apk进行签名
  7. mac下android studio安装的几个文件路径
  8. 如何获取Android设备名称(常用ADB命令介
  9. Android服务监控
  10. Fuel:Kotlin / Android最简单的HTTP网络库