当我在使用 WiFi 的设备上运行此应用程序时,它工作正常。但是当我使用移动网络或 3g 时,它会出错。它不适用于移动网络。
我正在使用这段代码:
connection = (HttpConnection) Connector.open(APIURL+ updateConnectionSuffix());
还有我的 ConnectionTools 类代码:
public String updateConnectionSuffix() {
String connSuffix;
if (DeviceInfo.isSimulator()) {
connSuffix = ";deviceside=true";
} else if ((WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED)
&& RadioInfo.areWAFsSupported(RadioInfo.WAF_WLAN)) {
connSuffix = ";interface=wifi";
} else {
String uid = null;
ServiceBook sb = ServiceBook.getSB();
ServiceRecord[] records = sb.findRecordsByCid("WPTCP");
for (int i = 0; i < records.length; i++) {
if (records[i].isValid() && !records[i].isDisabled()) {
if (records[i].getUid() != null
&& records[i].getUid().length() != 0) {
if ((records[i].getCid().toLowerCase().indexOf("wptcp") != -1)
&& (records[i].getUid().toLowerCase().indexOf(
"wifi") == -1)
&& (records[i].getUid().toLowerCase().indexOf(
"mms") == -1)) {
uid = records[i].getUid();
break;
}
}
}
}
if (uid != null) {
// WAP2 Connection
connSuffix = ";ConnectionUID=" + uid;
} else {
connSuffix = ";deviceside=true";
}
}
return connSuffix;
}
你能给我任何解决方案吗?
我们应该为移动网络或3g做些什么?