续上一篇的一半连接网络方式,这篇用blackberry官方的服务定制API(Service Book API)开发连接网络:
参看net.rim.device.api.servicebook的API,服务定制由服务记录组成,每个服务定义一个blackberry设备上有效的服务。
注:使用服务定制API是需要官方签名工具签名的
实例代码:
private 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;
}
// BES
if (cid.indexOf("ippp") != -1 && uid.indexOf("gpmds") == -1) {
srMDS = myRecord;
}
// WiFi
if (cid.indexOf("wptcp") != -1 && uid.indexOf("wifi") != -1) {
srWiFi = myRecord;
}
// Wap1.0
if (getConfigType(myRecord)==CONFIG_TYPE_WAP && cid.equalsIgnoreCase("wap")) {
srWAP = myRecord;
}
// Wap2.0
if (cid.indexOf("wptcp") != -1 && uid.indexOf("wifi") == -1 && uid.indexOf("mms") == -1) {
srWAP2 = myRecord;
}
// Unite
if(getConfigType(myRecord) == CONFIG_TYPE_BES && myRecord.getName().equals(UNITE_NAME)) {
srUnite = myRecord;
}
}
}
if(CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_BIS_B)){
coverageBIS=true;
bisHTTPLog.addlog("Coverage Status: Online");
}
if(CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_DIRECT)){
coverageTCP=true;
tcpHTTPLog.addlog("Coverage Status: Online");
coverageWAP=true;
wapHTTPLog.addlog("Coverage Status: Online");
coverageWAP2=true;
wap2HTTPLog.addlog("Coverage Status: Online");
}
if(CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_MDS)) {
coverageMDS=true;
mdsHTTPLog.addlog("Coverage Status: Online");
coverageUnite=true;
uniteHTTPLog.addlog("Coverage Status: Online");
}
if(WLANInfo.getWLANState()==WLANInfo.WLAN_STATE_CONNECTED){
coverageWiFi = true;
wifiHTTPLog.addlog("Coverage Status: Online");
}
}
一段连接WAP2.0的代码:
ServiceBook sb = ServiceBook.getSB();
ServiceRecord[] records = sb.findRecordsByCid("WPTCP");
String uid = null;
for(int i=0; i < records.length; i++)
{
//Search through all service records to find the
//valid non-Wi-Fi and non-MMS
//WAP 2.0 Gateway Service Record.
if (records[i].isValid() && !records[i].isDisabled())
{
if (records[i].getUid() != null && records[i].getUid().length() != 0)
{
if ((records[i].getUid().toLowerCase().indexOf("wifi") == -1) &&
(records[i].getUid().toLowerCase().indexOf("mms") == -1))
{
uid = records[i].getUid();
break;
}
}
}
}
if (uid != null)
{
//open a WAP 2 connection
Connector.open(_url + ";ConnectionUID=" + uid);
}
else
{
//Consider another transport or alternative action.
}
需要详细资料请查看:
1、What is - Network Diagnostic Tool:
http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/What_Is_-_Network_Diagnostic_Tool.html?nodeid=1450596&vernum=0
2、RIM BlackBerry Service Book Definitions:
https://www.wireless.att.com/support_static_files/KB/KB49057.html