Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何确定设备连接到internet时使用的网络_Java_Blackberry - Fatal编程技术网

Java 如何确定设备连接到internet时使用的网络

Java 如何确定设备连接到internet时使用的网络,java,blackberry,Java,Blackberry,到目前为止,我试图通过使用radio-info类来验证哪个网络处于打开状态,并检查radio-info.getNumberOfPacketsReceived()\Sent()中是否有任何更改,但如果有多个网络处于打开状态,这种方法是无用的。谁能给我指一下正确的方向吗 很抱歉拼写和语法错误,英语不是我的第一语言。您需要在URL后附加连接类型 public static String getConnectionString() { String connectionString = null;

到目前为止,我试图通过使用
radio-info
类来验证哪个网络处于打开状态,并检查
radio-info.getNumberOfPacketsReceived()\Sent()
中是否有任何更改,但如果有多个网络处于打开状态,这种方法是无用的。谁能给我指一下正确的方向吗


很抱歉拼写和语法错误,英语不是我的第一语言。

您需要在URL后附加连接类型

public static String getConnectionString() {

String connectionString = null;

// Simulator behaviour is controlled by the USE_MDS_IN_SIMULATOR
// variable.
if (DeviceInfo.isSimulator()) {

    connectionString = ";deviceside=true";
}

// Wifi is the preferred transmission method
else if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {

    connectionString = ";interface=wifi";
}

// Is the carrier network the only way to connect?
else if ((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT) {

    String carrierUid = getCarrierBIBSUid();

    if (carrierUid == null) {
        // Has carrier coverage, but not BIBS. So use the carrier's TCP
        // network

        connectionString = ";deviceside=true";
    } else {
        // otherwise, use the Uid to construct a valid carrier BIBS
        // request

        connectionString = ";deviceside=false;connectionUID="+carrierUid + ";ConnectionType=mds-public";
    }
}

// Check for an MDS connection instead (BlackBerry Enterprise Server)
else if ((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS) {

    connectionString = ";deviceside=false";
}

// If there is no connection available abort to avoid hassling the user
// unnecssarily.
else if (CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_NONE) {
    connectionString = "none";

}

// In theory, all bases are covered by now so this shouldn't be reachable.But hey, just in case ...
else {

    connectionString = ";deviceside=true";
}



return connectionString;

}

/**
 * Looks through the phone's service book for a carrier provided BIBS
 * network
 * 
 * @return The uid used to connect to that network.
 */
 private synchronized static String getCarrierBIBSUid() {
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;
}

它将决定可用的网络类型。

您能给出一个您想要实现的目标吗?即使启用了wifi,一些应用程序仍然可以使用radio Connection。我想采用Android应用程序,通过移动网络和wifi测量互联网流量。在Android中,我使用\TrafficStats.getMobileRxBytes\和\TrafficStats.getTotalRxBytes\。在blackberry SDK中,所有统计数据都封装在\Radio Info.getNumberOfPacketsReceived()\Sent()\中,因此现在我需要确定当其他应用程序使用internet时使用的是哪个网络。感谢您的响应和cod示例,但我不会尝试通过开放网络创建到internet的连接。我想确定其他应用程序使用internet时使用的是哪个网络。
con = (HttpConnection) Connector.open(url + getConnectionString());