類似的方法,但一個,我覺得有點不是理查德的思想更好地上面,因爲(因爲JAD文件可能針對不同的BB OS版本不同重要),客戶端不需要硬編碼JAD路徑是這樣的:
創建一個接受應用程序名稱和當前應用程序版本作爲輸入的簡單網頁(php,jsp,servlet,cgi,whatever);如果你需要它,在輸入中也包括操作系統版本。
該URL將由客戶端通過獲取適當的數據(詳細信息如下)並將其附加到已知的基本URL來構建。
該網頁將解析信息,並計算出適當的版本運行。
- 請注意,你可能並不需要所有的上述信息:如果你只有您的應用程序的一個下載的版本,你真的只需要設備發送的客戶端軟件版本,沒有別的。正確版本的計算可以是一個簡單的硬編碼檢查(如果($ 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 URL
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;
}
和借鑑E:簡單LineInputStream實施
http://svn.bbssh.org/trunk/BBSSH_Common/src/org/bbssh/io/LineInputStream.java
採樣輸入URL 1 此網址由客戶構建併發送至服務器:
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
你能不能提供這樣的代碼示例?對不起,我對Blackberry Development非常陌生,我知道在某些時候我需要這樣做 – Chris 2010-06-09 14:00:45
簡短的回答是否定的。答案的理由是,在連接方法(BES,BIS-B,APN)和應用類型方面有足夠的變量,最終,更好地學習如何執行每一步,然後把它以一種合理的方式與您的應用程序一起使用。如果您對Blackberry Development非常陌生,那麼您可能希望將這部分應用放在一邊,直到您做好準備。 – Richard 2010-06-09 16:54:59