BlackBerry手機上,Java編程實現程式中下載並安裝多個cod,升級自己

來源:互聯網
上載者:User

目錄:src

說明:根據RIM提供的例子代碼,稍作修改:

1 . 判斷網路連接情況是否支援Direct串連(原代碼是判斷 MDS串連情況)

2.  判斷網路連接情況是中國移動/中國電信/中國聯通以便採取不同的APN cmnet 3gnet或者是使用WAP 2.0串連,根據判斷使用對應的網路連接(原代碼是使用MDS串連)

3.  去掉原代碼的titlebar,原因是BlackBerry SDK 5.0 沒有相應的API


目錄:build.ota

檔案:a.jad    CodeModuleInstallerSample.cod

說明:編譯好的安裝程式,使用的時候,把jad和cod檔案放在apache的網站任意目錄下面,手機上即可OTA安裝

為方便使用者OTA安裝,jad檔案名稱字改為 a.jad 


目錄:installerSample

下面有三個之目錄和一個說明檔案,ClorfulTimeExtracted,GooNuu,NetworkSample,applicationList.txt

說明:在程式碼中和次目錄下面的多個txt 檔案中,hardcode了安裝路徑指向 http://shanghai.springworks.info/installerSample/applicationList.txt


程式原始碼下載猛擊這裡


測試程式直接下載

 安裝後,點擊菜單”checkfor update”,等一會,兩個程式就安裝好了(goonuu,colorfultime)。

註:這兩個程式安裝後,可以直接點擊程式表徵圖運行,不需要重新啟動



==================================================================================

後記:

在程式A中用API簡單的重新安裝程式A的cod檔案,會出現不提示使用者restart機器,使用者不拔電池板更新過的程式A不起作用的情況。

那麼程式如何升級自己呢 。方法如下:

step 1: 刪除自己。(梅花寶典,欲練神功,引刀自宮)

step 2: 下載新版本的cod檔案

step 3: 安裝cod檔案

原文參考:http://blog.vimviv.com/blackberry/upgrade-application-blackbery/

public void upgrade() {//Delete it self. int handle = CodeModuleManager.getModuleHandle(moduleName); if (handle != 0) { int success = CodeModuleManager.deleteModuleEx(handle, true); System.out.println("response: " + success); }// Download new cod files(included sibling files).byte[] codBuff = null;String[] cod = new String[3];//assuming that application contents 3 cod files.cod[0] = getViaHttp("moduleName");cod[1] = getViaHttp("moduleName-1");cod[2] = getViaHttp("moduleName-2");System.out.println("download complete");int newHandle = 0;// API REFERENCE:// You need to write the data in two separate chunks.// The first data chunk must be less thank 64KB in size.int MAXAPPEND = 61440; // 1024*60;for (int i = 0; i < 3; i++) {codBuff = cod[i].getBytes();if (codBuff.length > MAXAPPEND) {newHandle = CodeModuleManager.createNewModule(codBuff.length,codBuff, MAXAPPEND);boolean appendSucc = CodeModuleManager.writeNewModule(newHandle, MAXAPPEND, codBuff, MAXAPPEND,codBuff.length - MAXAPPEND);codBuff = null;} else {newHandle = CodeModuleManager.createNewModule(codBuff.length,codBuff, codBuff.length);}//install the moduleif (newHandle != 0) {int savecode = CodeModuleManager.saveNewModule(newHandle, true);if (savecode == CodeModuleManager.CMM_OK_MODULE_OVERWRITTEN)System.out.println("The operation completed successfully; a module was overwritten and marked for deletion in the process.");}System.out.println(i + " module installed");}//restart the blackberry if reuiredif (CodeModuleManager.isResetRequired())CodeModuleManager.promptForResetIfRequired();}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.