Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check wifi condition in Blackberry application

I have developed an application for blackberry devices. The application is working fine if it uses internet via data service provider.

I have BB 9550 and I want to use my application using wifi. I tried a lot but I cant get proper answer to check wifi condition.

How we can differentiate to run our application for wifi or data service provider?

like image 324
Hitarth Avatar asked Sep 21 '11 06:09

Hitarth


1 Answers

For checking wifi is connected or not the following method will help you.

 public static boolean isWifiConnected()
    {
        try
        {
            if (RadioInfo.getSignalLevel(RadioInfo.WAF_WLAN) != RadioInfo.LEVEL_NO_COVERAGE)
            {
                return true;
            }
        }
        catch(Exception e)
        {
            System.out.println("Exception during get WiFi status");
        }
        return false;
    } 

if wifi is not connected the following methods will help to add data service.

public static String getConnParam(){
        String connectionParameters = "";
        if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
        // Connected to a WiFi access point
        connectionParameters = ";interface=wifi";
        } else {
        int coverageStatus = CoverageInfo.getCoverageStatus();
        ServiceRecord record = getWAP2ServiceRecord();
        if (record != null
        && (coverageStatus & CoverageInfo.COVERAGE_DIRECT) ==
        CoverageInfo.COVERAGE_DIRECT) {
        // Have network coverage and a WAP 2.0 service book record
        connectionParameters = ";deviceside=true;ConnectionUID="
        + record.getUid();
        } else if ((coverageStatus & CoverageInfo.COVERAGE_MDS) ==
        CoverageInfo.COVERAGE_MDS) {
        // Have an MDS service book and network coverage
        connectionParameters = ";deviceside=false";
        } else if ((coverageStatus & CoverageInfo.COVERAGE_DIRECT) ==
        CoverageInfo.COVERAGE_DIRECT) {
        // Have network coverage but no WAP 2.0 service book record
        connectionParameters = ";deviceside=true";
        }

    }
        return connectionParameters;
    }
        private static  ServiceRecord getWAP2ServiceRecord() {
            ServiceBook sb = ServiceBook.getSB();
            ServiceRecord[] records = sb.getRecords();
            for(int i = 0; i < records.length; i++) {
            String cid = records[i].getCid().toLowerCase();
            String uid = records[i].getUid().toLowerCase();

            if (cid.indexOf("wptcp") != -1 &&
            uid.indexOf("wifi") == -1 &&
            uid.indexOf("mms") == -1) {
            return records[i];
            }
            }
            return null;
            }

Example to use above methods.

String connParams=(isWifiConnected())?";interface=wifi":getConnParam();

Hope This will help you

like image 159
koti Avatar answered Sep 24 '22 23:09

koti