在黑莓上扫描可用的Wi-Fi网络

3

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

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

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

我正在寻找适用于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文档来实现,但我没有成功。如果您对此有任何想法或任何示例代码,将非常有帮助。

你找到解决方案了吗?我正在寻找有关热点类的示例代码,但很难找到任何相关资料。 - Tjaart
1个回答

5

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

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

/**
 * 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;
}

我运行了RIM NetworkDiagnosticTool,但它似乎没有提供任何可用的多个WiFi网络列表。我还检查了源代码,但没有看到任何收集(但不显示)该信息的内容。 - Nate

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接