一种类似的方法,但我发现它比 Richard 上面的想法要好一些,因为客户端不需要这种方式的硬编码 JAD 路径(很重要,因为不同 BB OS 版本的 JAD 文件可能不同):
创建一个接受应用名称和当前应用版本作为输入的简单网页(php、jsp、servlet、cgi 等);如果需要,还可以在输入中包含操作系统版本。
此 URL 将由客户端通过获取适当的数据(详细信息如下)并将其附加到已知的基本 URL 来构建。
-
网页将解析信息,并计算出要运行的正确版本。
- 请注意,您可能不需要上述所有信息:如果您的应用程序只有一个可下载版本,您实际上只需要设备发送客户端软件版本,无需其他任何信息。正确版本的计算可以是简单的硬编码检查 (if ($version != LATEST_VERSION)) 或更复杂的东西,包括查找数据库或其他地方。
- 此页面将输出纯文本,非 HTML。它将写入三个值,每行一个:
- “y”如果需要更新,“n”如果不需要。
- 此客户端使用的最新版本。仅当您希望客户端显示它时才需要这样做。
- 正确 JAD 的下载 URL。
- 客户端应用程序将解析该数据,如果第一个标志为“Y”,将显示消息“当前版本为(第二行的内容)。您要更新吗?”选择更新时,它将启动第三行中提供的 URL。
参考
获取应用程序版本
import net.rim.device.api.system.ApplicationDescriptor;
...
// Returns current app version in the format Major.Minor.Minor.Build, eg 1.5.1.123
String version = ApplicationDescriptor.currentApplicationDescriptor().getVersion();
获取硬件和平台信息
import net.rim.device.api.system.ApplicationDescriptor;
...
// Obtain the platform version string in the format A.B.C.DDD, eg 5.0.0.464
String softwareVersion = DeviceInfo.getSoftwareVersion();
// Obtain the hardware name:
String hardwareName = DeviceInfo.getDeviceName();
启动 HTTP 网址
import net.rim.blackberry.api.browser.Browser;
Browser.getDefaultSession().displayPage("http://example.com");
读取 HTTP 文件
String url = "full/url/assembled/with/data/above"
// YOU assemble "url" value - and include more error handling than is here in this sample:
HttpConnection conn;
try {
conn = ConnectionHelper.getHttpConnection(url);
LineInputStream stream = new LineInputStream(conn.openInputStream());
String lineOneYesNo = stream.readLine(true);
String lineTwoCurrentVersion = stream.readLine(true))
String lineThreeDownloadURL = stream.readLine(true))
// ***
// * Parse the data above and handle as described.
// ***
return data;
} catch (IOException e) {
// Add appropriate erorro handling here
return;
}
getHttpConnection 实现
public static HttpConnection getHttpConnection(String URL) throws IOException {
HttpConnection c = null;
StringBuffer conn = new StringBuffer(URL);
// *** IMPORTANT ***
// YOU must define this method below, as it will append
// values to the connection string based on connection
// type (MDS, TCP, WIFI, WAP2, etc)
//
configureConnectionString(conn);
c = (HttpConnection) Connector.open(conn.toString());
int rc = c.getResponseCode();
if (rc != HttpConnection.HTTP_OK) {
throw new IOException("HTTP Error: " + rc);
}
return c;
}
参考:简单的 LineInputStream 实现
http://svn.bbssh.org/trunk/BBSSH_Common/src/org/bbssh/io/LineInputStream.java
示例输入 URL 1
此 URL 由客户端构建并发送到服务器:
http://example.com/versioncheck.do/app-name/hardware-name/os-version/app-version
e.g. http://example.com/versioncheck.do/MyApplication/Bold9000/5.0.466/1.5.1.0
示例输入 URL 2
同一事物的替代格式:
http://example.com/versioncheck.php?appName=A&hardwareName=B&osVersion=C&appVersion=D
e.g. http://example.com/versioncheck.php?appName=?MyApplication&hardwareName=Bold9000?osVersion=5.0.466&appVersion=1.5.1.0
样本输出
y
1.3.1.125
http://example.com/ota/5.0.0/MyApp.jad