我正在忙於編寫一個程序,該程序將GPS座標傳輸到服務器,然後通過手機將座標用於計算。但我一直在用黑莓手機撞牆。我已經構建了Android應用程序,它工作的很好,但似乎無法通過真正的黑莓設備與服務器聯繫。我已經在模擬器中測試了該應用程序,並且它可以很好地工作,但是當我將它安裝在真實的手機上時,我無法請求手機。黑莓連接噩夢
我已經閱讀了不少關於祕密字符串在URL的末尾追加所以我適應了一些演示代碼,讓我第一個可用的運輸,但仍然沒有...
的應用程序進行簽名,然後我通常會通過eclipse進行調試,或者直接在.jad文件的設備上進行安裝,並允許應用程序獲得所需的權限。
當前的代碼是從Blackberry SDK中的HTTP連接演示改編而來的。
你可以看看,給我一些方向。我在這裏失去了太多的頭髮......
後端服務是保持運行:
ConnectionFactory connFact = new ConnectionFactory();
ConnectionDescriptor connDesc = connFact.getConnection(getUrl());
// Open the connection and extract the data.
try {
// StreamConnection s = null;
// s = (StreamConnection) Connector.open(getUrl());
HttpConnection httpConn = (HttpConnection) connDesc.getConnection();
/* Data is Read here with a Input Stream */
任何想法:
public void run() {
System.out.println("Starting Loop");
Criteria cr = new Criteria();
cr.setHorizontalAccuracy(Criteria.NO_REQUIREMENT);
cr.setVerticalAccuracy(Criteria.NO_REQUIREMENT);
cr.setCostAllowed(false);
cr.setPreferredPowerConsumption(Criteria.NO_REQUIREMENT);
cr.setPreferredResponseTime(1000);
LocationProvider lp = null;
try {
lp = LocationProvider.getInstance(cr);
} catch (LocationException e) {
System.out.println("*****************Exception" + e);
}
if (lp == null) {
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
Dialog.alert("GPS not supported!");
return;
}
});
} else {
System.out
.println(lp.getState() + "-" + LocationProvider.AVAILABLE);
switch (lp.getState()) {
case LocationProvider.AVAILABLE:
// System.out.println("Provider is AVAILABLE");
while (true) {
Location l = null;
int timeout = 120;
try {
l = lp.getLocation(timeout);
final Location fi = l;
System.out.println("Got a Coordinate "
+ l.getQualifiedCoordinates().getLatitude()
+ ", "
+ l.getQualifiedCoordinates().getLongitude());
System.out.println("http://" + Constants.website_base
+ "/apis/location?device_uid=" + Constants.uid
+ "&lat="
+ l.getQualifiedCoordinates().getLatitude()
+ "&lng="
+ l.getQualifiedCoordinates().getLongitude());
if (!_connectionThread.isStarted()) {
fetchPage("http://"
+ Constants.website_base
+ "/apis/location?device_uid="
+ Constants.uid
+ "&lat="
+ l.getQualifiedCoordinates().getLatitude()
+ "&lng="
+ l.getQualifiedCoordinates()
.getLongitude());
} else {
createNewFetch("http://"
+ Constants.website_base
+ "/apis/location?device_uid="
+ Constants.uid
+ "&lat="
+ l.getQualifiedCoordinates().getLatitude()
+ "&lng="
+ l.getQualifiedCoordinates()
.getLongitude());
}
Thread.sleep(1000 * 60);
} catch (LocationException e) {
System.out.println("Location timeout");
} catch (InterruptedException e) {
System.out.println("InterruptedException"
+ e.getMessage());
} catch (Exception ex) {
System.err.println(ex.getMessage());
ex.printStackTrace();
}
}
}
}
我的連接與製造?
您不必如果您使用的是OS 5.0或更高附加任何東西,只要使用連接工廠。 – 2012-02-06 10:10:53
我正在使用ConnectionFactory?我用錯了嗎? – 2012-02-06 10:16:55
你確定這個問題存在聯繫嗎?他們是否超時?或者,GPS可能會超時(預計BB在1分鐘左右)。 – 2012-02-06 14:15:10