一.获取当前手机支持的接入方式
public void initializeTransportAvailability() {
ServiceBook sb = ServiceBook.getSB();
ServiceRecord[] records = sb.getRecords();
for (int i = 0; i < records.length; i++) {
ServiceRecord myRecord = records[i];
String cid, uid;
if (myRecord.isValid() && !myRecord.isDisabled()) {
cid = myRecord.getCid().toLowerCase();
uid = myRecord.getUid().toLowerCase();
// BIS
if (cid.indexOf("ippp") != -1 && uid.indexOf("gpmds") != -1) {
srBIS = myRecord;
}
// WIFI
if (cid.indexOf("wptcp") != -1 && uid.indexOf("wifi") != -1) {
// srWiFi = myRecord;
}
// Wap2.0
if (cid.indexOf("wptcp") != -1 && uid.indexOf("wifi") == -1
&& uid.indexOf("mms") == -1) {
srWAP2 = myRecord;
}
}
}
if (CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_BIS_B)) {
coverageBIS = true;
}
if (CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_DIRECT)) {
coverageTCP = true;
coverageWAP2 = true;
}
if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
coverageWiFi = true;
}
if (CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_DIRECT)) {
coverageTCP = true;
}
}
二.wifi方式创建http
HttpConnection httpConnection =null;
String httpurl = url+";interface=wifi"
httpConnection = (HttpConnection) Connector.open(httpUrl,
Connector.READ_WRITE);
三 BIS方式创建http
HttpConnection httpConnection =null;
String bisUid = srBIS.getUid();
String httpurl = url+";deviceside=false;connectionUID="
+ bisUid + ";ConnectionType=mds-public";
httpConnection = (HttpConnection) Connector.open(httpUrl,
Connector.READ_WRITE);
四 WAP2方式创建http
HttpConnection httpConnection =null;
String wap2Uid = srWAP2.getUid();
String httpurl = ";deviceside=true" + ";ConnectionUID="
+ wap2Uid;
httpConnection = (HttpConnection) Connector.open(httpUrl,
Connector.READ_WRITE);
五 直连方式创建http
HttpConnection httpConnection =null;
String httpurl = ";deviceside=true"
httpConnection = (HttpConnection) Connector.open(httpUrl,
Connector.READ_WRITE);
此外还有BES,Unite,WAP1等方式,因为无法测试就不写了。以为四种方式都测试可行。