Check wifi status in Blackberry app

I developed an application for Blackberry devices. An application works fine if it uses the Internet through a data service provider.

I have a BB 9550 and I want to use my application using Wi-Fi. I tried a lot, but I can not get the correct answer for checking wifi status.

How can we distinguish between launching our Wi-Fi application or data service provider?

+7
source share
2 answers

To check whether a Wi-Fi connection is available 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 add a 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; } 

An example of using the above methods.

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

Hope this helps you

+10
source

try the following:

 private static String getParameters() { if (GetWiFiCoverageStatus()) { return ";deviceside=true;interface=wifi"; } else { return yourParametersForEdge } } private static boolean GetWiFiCoverageStatus() { if((WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED)) { return true; } else return false; } 

And when you need to connect, you will need to add parameters to the url:

 yourUrl = yourUrl + getParameters(); 
+3
source

All Articles