在黑莓 jre 5.0 中,如果已连接互联网但无法浏览,则应用程序在使用宁静服务时没有响应。请指导我是否有任何方法可以设置响应超时?
我正在使用此代码来使用服务。
static HttpConnection con = null;
static InputStream is = null;
static StringBuffer rawResponse;
public static String Call(String url) throws IOException {
try {
url = url + getConnectionString() + ";";
if (CheckConn()) {
con = (HttpConnection) Connector.open(url, Connector.READ_WRITE, true);
is = con.openInputStream();
byte[] responseData = new byte[10000];
int length = 0;
rawResponse = new StringBuffer();
while (-1 != (length = is.read(responseData))) {
rawResponse.append(new String(responseData, 0, length));
}
} else {
Status.show("Internet service is not avaiable.");
}
} catch (IOException ex) {
Status.show("Internet is not responding");
} finally {
try {
is.close();
con.close();
} catch (Exception e) {
Status.show(e.getMessage());
}
}
return rawResponse.toString();
}
public static String getConnectionString() {
String connectionString = "";
if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
connectionString = ";interface=wifi";
}
else if ((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS) {
connectionString = ";deviceside=false";
}
else if ((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT) {
String carrierUid = getCarrierBIBSUid();
if (carrierUid == null) {
connectionString = ";deviceside=true";
} else {
connectionString = ";deviceside=false;connectionUID=" + carrierUid + ";ConnectionType=mds-public";
}
}
else if (CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_NONE) {
connectionString = ";None";
}
return connectionString;
}
public static String getCarrierBIBSUid() {
net.rim.device.api.servicebook.ServiceRecord[] records = ServiceBook.getSB().getRecords();
int currentRecord;
for (currentRecord = 0; currentRecord < records.length; currentRecord++) {
if (records[currentRecord].getCid().toLowerCase().equals("ippp")) {
if (records[currentRecord].getName().toLowerCase().indexOf("bibs") >= 0) {
return records[currentRecord].getUid();
}
}
}
return null;
}