我正在忙于编写一个程序,该程序将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