When I run this application on a device using the WiFi it's working fine. But when I am using a mobile network or 3g it's giving an error. It's not working on the mobile network.
I am using this code:
connection = (HttpConnection) Connector.open(APIURL+ updateConnectionSuffix());
And my ConnectionTools class code:
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;
}
Can you give me any solutions?
What should we do for the mobile network or 3g?
Try this code.
Replace this function by your updateConnectionSuffix().
Let me explain : - This is for connection using mobile network 2g or 3g any network" just copy & paste & enjoy
String url = "vm.b24esolution.com:9090";
final HttpConnection connection = (HttpConnection) Connector.open("socket://"+url+updateConnectionSuffix()+";apn=rim.net.gprs;tunnelauthusername =;tunnelauthpassword=",Connector.READ_WRITE);