目录: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 module
if (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 reuired
if (CodeModuleManager.isResetRequired())
CodeModuleManager.promptForResetIfRequired();
}