views:

444

answers:

2

Is there any RIM API available which will help to get the list of available network service or only Wi-Fi networks for a device and set selected network access point for any network communications?

Is it possible for my app to disable the Mobile networks like GPRS, WAP, etc?

Example:
When the application is started it should scan for WiFi connections, even if there are no previous WiFi network access points set on the device, and list the available WiFi connections. Then the user will select the appropriate WiFi connection to connect for any network communication. Outside the application any internet communication, like the browser or any other application, should be done through the same selected WiFi connection. The scanning for WiFi and setting the connection is almost similar to Blackberry WiFi Setup.

I am looking to do this for BlackBerry OS 4.5, 4.7 and 5.0.

+1  A: 

well , to scan for all available network for application you can use NetworkDiagnostic tool from RIM link text

other piece of code to scan for your phone connectivity and get the best connection string can find it on link text:

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

    // Wifi 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;
}   
Galaxy
A: 

Hi Galaxy,

Thanks for ur reply and i really appreciate as you shared some code to explain the connectivity in blackberry.

But the thing is i m looking for wifi scanning through application. Its like through application i can able to scan available wifi access points or hotspots and set one of access point by selecting it to device, then connect to it for communication.

Basically its like how we set the wifi connection in "Manage connetion" of blackberry. similar thing i have to do through applicaiton.

From BB forums i got to know there is package in OS v5.0 i.e net.rim.device.api.wlan.hotspot package to get the WiFi hotspots. But after a long search i dint find any sample example or much explanation on it. As i am trying to implement by looking into its api docs but not succeded.

If you have any idea related to this or any sample code will be very helpful.

once again thanks for ur help.

amsiddh
For future reference, you shouldn't expand on your question by posting an answer to it - it's best to edit the question so that people reading it for the first time will get all the information.
DJClayworth