Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

New Contributor
Posts: 8
Registered: ‎12-20-2011
My Device: 9700
My Carrier: XL Ind

Scanning wifi network in app

I think i have read dozens of threads discussing about using HotSpotClient to scan wifi network in app.

The best solution so far is http://supportforums.blackberry.com/t5/Java-Development/How-to-scan-for-available-networks-for-devic....


Here is the code :

public class HotspotCredentialsAgentEnabler extends HotspotCredentialsAgent {
        private String _userName;
        private String _password;
        private int _crAgent_Preference;
        public int getCredentialsControlPreference() {
            return _crAgent_Preference;
        public String getPassword() {
            return _password;
        public String getUsername() {
            return _userName;
        protected  void setCredentialsControlPreference(int control) {
            this._crAgent_Preference = control;
        public void setPassword(String password) {
            this._password = password;
        public void setUsername(String userName) {
            this._userName = userName;
        public boolean validateCredentials(String username, String password) {
            //for cross verification
            return true;

    public class HotspotClientEnabler extends HotspotClient {

        private StringBuffer wLanInfoBuff;
        public HotspotClientEnabler(HotspotCredentialsAgent hotspotCrAgent, HotSpotAuthAgentEnabler hotSpotAuthAgent, int supportednetworkTypes) {

            super(hotspotCrAgent, hotSpotAuthAgent, supportednetworkTypes);
        public String getClientName() {      
            return "Any Name";      
        public  HotspotInfo[] getSupportedNetworks(WLANAPInfo[] networks) {            
            // here u can read the WLANInfo.WLANAPInfo[], and try to get the open n/w, the one which you want to connect
            // and return this as a first element of the HotspotInfo array
            // you can read all properties using getHotSpotInfo(...) and can set additional properties to
            // the HotspotInfo
        	String text = "Called \n";
			HotspotInfo[] hotspotInfo = new HotspotInfo[networks.length];
			for(int i = 0; i<networks.length; i++)
				text += networks[i].getBSSID() + "\n";
				text += networks[i].getSignalLevel() + "\n";
				text += networks[i].toString() + "\n ";
				hotspotInfo[i]=new HotspotInfo(networks[i], false);
			final String shownText = text;
			UiApplication.getUiApplication().invokeLater(new Runnable() {
				public void run() {
			return hotspotInfo; //return only open networks        

        public void getHotSpotInfo(WLANAPInfo wLanInfo) {
            wLanInfoBuff = new StringBuffer();
            String ssid = "";
            if(wLanInfo != null) {
                wLanInfoBuff.append("**Profile Name*****"+wLanInfo.getProfileName());
                ssid = wLanInfo.getSSID();

public class HotSpotAuthAgentEnabler extends HotspotAuthenticationAgent {
        public void login(HotspotInfo hotspot) {
        public void logout(HotspotInfo hotspot) {
        public void cancelLogin(HotspotInfo hotspot) {
        public int getSessionState() {
            int sessionState = this.getSessionState();
            return sessionState;
        public void probeNetwork(HotspotInfo hotspot){

//In screen constructor :
try {

            HotspotCredentialsAgentEnabler hotSpotCredentialsAgent = new HotspotCredentialsAgentEnabler();

            HotspotStatusListener listener = new HotspotStatusListener() {
				public void updateStatus(AuthenticationStatusEvent event) {
            HotSpotAuthAgentEnabler hotSpotAuthAgentEnabler = new HotSpotAuthAgentEnabler();

             hotspotClientEnabler = new HotspotClientEnabler(HotspotCredentialsAgent.getSystemHotspotCredentialsAgent(),
             hotSpotAuthAgentEnabler, HotspotClient.NETWORK_TYPE_MANUAL );

        } catch (HotspotException hotspotExc) {


The code works very nice in simulator. However, in device, this become so complicated.


First time I run the app, i don't see any wifi network is listed. I need to put my test app in background and went to Manage Connection->setup wifi network.


There I see prompt for the registration. So I need to allow it register and it brings me to the screen that has the "Scan for network", "manually Add Network" ... buttons.


So I pressed "Scan for Network" and after a few seconds I hit break point in my getSupportedNetworks() and WLANInfo.WLANAPInfo[] networks has 5 networks.


My question is :

Is there a way to bypass the approval dialog?

Is there a way to force a wifi scan programmatically without user interaction?

Or is there any way to get list of available open network without using this HotspotClient class? I just need these list, no need to connect to anything.


New Contributor
Posts: 8
Registered: ‎12-20-2011
My Device: 9700
My Carrier: XL Ind

Re: Scanning wifi network in app

Anybody can help me? Maybe my post is too long.

Let's make it clear.


All i want to do is  to get list of available wifi network that can be detected.

Until now, i find that there's only 1 way to do that which is using the HotspotClientRegistry (http://www.blackberry.com/developers/docs/5.0.0api/net/rim/device/api/wlan/hotspot/HotspotClientRegi...).


However, when it's used on the real device, the user need to put the app on the background and there will be a notification to grant permission through the menu Manage Connection->setup wifi network.


Is there any way to avoid this? Or is there any way to get the list of wifi network without using this HotspotClientRegistry?

As a note, when i try to run it on the simulator, i don't need to go to the menu to grant permission and get the wifi list easily.

New Contributor
Posts: 2
Registered: ‎08-05-2012
My Device: 8520
My Carrier: personal

Re: Scanning wifi network in app



This is the solution:


HotspotClientRegistry.add(hotspotClientEnabler, ApplicationDescriptor.currentApplicationDescriptor());

This will trigger a new scan.



A. M.