0
工作,我有以下代码:的HttpConnection不与3G
HttpConnection httpCon = null;
InputStream fileIn = null;
try
{
httpCon = (HttpConnection) Connector.open(url + getConnectionSuffix(), Connector.READ);
httpCon.setRequestMethod(HttpConnection.GET);
}
catch (Exception e)
{
.......
}
.............
和
private String getConnectionSuffix()
{
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上它不起作用(其他应用程序,对于exp:浏览器效果很好)。哪里不对?
看看这个链接http://stackoverflow.com/questions/11670246/httpconnection-connect-with-mobile-network-or-3g/11724735#11724735 – 2012-08-06 13:51:09
什么是你的traget os?如果它是5+,则可以使用ConnectionFactory而不是手动检测连接传输。 – 2012-08-07 05:06:27