WPS Office手機版調用介面代碼指導帖之二 [複製連結]

來源:互聯網
上載者:User

標籤:putextra   style   view   參數   image   sha   open   package   ref   

原文連結:http://bbs.wps.cn/thread-22349340-1-1.html

從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




<ignore_js_op>

支援方式.JPG (20.75 KB, 下載次數: 1132)

 

<ignore_js_op>

儲存檔案.JPG (19.68 KB, 下載次數: 1132)

 

<ignore_js_op>

open file.JPG (78.29 KB, 下載次數: 916)

 

<ignore_js_op>

關閉檔案.JPG (35.16 KB, 下載次數: 945)

 

<ignore_js_op>

testThirdInterface.rar

 

45.21 KB, 下載次數: 2296

WPS Office手機版調用介面代碼指導帖之二 [複製連結]

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.