3

是否有任何可用的RIM API 可帮助获取设备的可用网络服务列表或仅 Wi-Fi 网络,并为任何网络通信设置选定的网络接入点?

我的应用程序是否可以禁用 GPRS、WAP 等移动网络?

示例:
当应用程序启动时,它应该扫描 Wi-Fi 连接,即使设备上没有设置以前的 Wi-Fi 网络接入点,并列出可用的 Wi-Fi 连接。然后用户将选择适当的 Wi-Fi 连接来连接任何网络通信。在应用程序之外,任何 Internet 通信,如浏览器或任何其他应用程序,都应通过相同的选定 Wi-Fi 连接完成。扫描 Wi-Fi 和设置连接几乎与 BlackBerry Wi-Fi Setup 类似。

我希望为 BlackBerry OS 4.5、4.7 和 5.0 执行此操作。

更新

问题是我正在寻找通过应用程序进行 Wi-Fi 扫描。就像通过应用程序,我可以扫描可用的 Wi-Fi 接入点或热点,并通过将其选择到设备来设置其中一个接入点,然后连接到它进行通信。

基本上就像,我们如何在黑莓的“管理连接”中设置 Wi-Fi 连接?我必须通过应用程序做类似的事情。

从一些黑莓论坛我了解到 OS v5.0 中有一个包,即一个net.rim.device.api.wlan.hotspot包来获取 Wi-Fi 热点。但是经过长时间的搜索,我没有找到任何示例或太多解释。正如我试图通过查看其 API 文档来实现的,但我没有成功。

如果您对此有任何想法或任何示例代码,这将非常有帮助。

4

1 回答 1

5

好吧,要扫描应用程序的所有可用网络,您可以使用 RIM 的NetworkDiagnostic 工具

可以在如何在任何 BlackBerry 设备上可靠地建立网络连接中找到用于扫描手机连接并获得最佳连接字符串的另一段代码,

/**
 * Determines what connection type to use and returns the necessary string to use it.
 * @return A string with the connection info
 */
private static String getConnectionString()
{
    // This code is based on the connection code developed by Mike Nelson of AccelGolf.
    // http://blog.accelgolf.com/2009/05/22/blackberry-cross-carrier-and-cross-network-http-connection
    String connectionString = null;

    // Simulator behavior is controlled by the USE_MDS_IN_SIMULATOR variable.
    if (DeviceInfo.isSimulator())
    {
            if (UploaderThread.USE_MDS_IN_SIMULATOR)
            {
                    logMessage("Device is a simulator and USE_MDS_IN_SIMULATOR is true");
                    connectionString = ";deviceside=false";
            }
            else
            {
                    logMessage("Device is a simulator and USE_MDS_IN_SIMULATOR is false");
                    connectionString = ";deviceside=true";
            }
    }

    // Wi-Fi is the preferred transmission method.
    else if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED)
    {
        logMessage("Device is connected via Wifi.");
        connectionString = ";interface=wifi";
    }

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

        String carrierUid = getCarrierBIBSUid();
        if (carrierUid == null)
        {
            // Has carrier coverage, but not BIBS.  So use the carrier's TCP network
            logMessage("No Uid");
            connectionString = ";deviceside=true";
        }
        else
        {
            // otherwise, use the Uid to construct a valid carrier BIBS request
            logMessage("uid is: " + carrierUid);
            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)
    {
        logMessage("MDS coverage found");
        connectionString = ";deviceside=false";
    }

    // If there is no connection available abort to avoid bugging the user unnecssarily.
    else if (CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_NONE)
    {
        logMessage("There is no available connection.");
    }

    // In theory, all bases are covered so this shouldn't be reachable.
    else
    {
        logMessage("no other options found, assuming device.");
        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 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;
}
于 2010-06-13T08:56:12.100 回答