Welcome!

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

Reply
Developer
amsiddh
Posts: 142
Registered: ‎06-26-2009
My Device: Not Specified

How to scan for available networks for device from application?

Hi All,

 

1. 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?

 

2. Is it possible programmatically to disable the Mobile networks like GPRS, WAP, etc? 

 

For Ex:

When a application is started it should scan for WiFi connections (even if there are no previous WiFi network access points are set on device) and list the available WiFi connection. Then user will select the appropriate WiFi connection to connect for any network communication. Outside the application any internet communication (like browser or any other application) should done through same selected WiFi connection.

The scanning for WiFi and setting the connection is almost similar to Blackberry WiFi Setup.

 

If anyone know how to implement this using available RIM API and let me know its possible or not. Please share if anyone have any code snippet related to this.

 

I am looking for OS v4.5, 4.7, and 5.0. 

 

Thanks,

Siddh.

Please use plain text.
Developer
amsiddh
Posts: 142
Registered: ‎06-26-2009
My Device: Not Specified

Re: How to scan for available networks for device from application?

Hi,

 

After searching on forums, i got to know there are some packages are added in OS v5.0 i.e net.rim.device.api.wlan.hotspot package to get the WiFi hotspots. But i am still in confusion of how start for this issue. If anyone know how to implement this, please help... since from last post i am looking for some help on this topic.. :smileysad:

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to scan for available networks for device from application?

1. HotSpot in OS 5.0 is all there is, it is only good for non encrypted networks.  Search the forum for other Threads that discuss this API. 

 

2. Not that I am aware off. 

Please use plain text.
Contributor
kims
Posts: 10
Registered: ‎05-31-2010
My Device: Bold
My Carrier: vodafone

Re: How to scan for available networks for device from application?

Hi,

 

Please refer below link from the forum where it is discussed.

 

http://supportforums.blackberry.com/t5/Java-Development/WiFi-hotspot-availability/m-p/518853#M105065

 

Thanks.

Kims

 

Please use plain text.
Developer
amsiddh
Posts: 142
Registered: ‎06-26-2009
My Device: Not Specified

Re: How to scan for available networks for device from application?

Hi,

@peter_strainge

thanks for ur reply

on HotSpot API i didnt found much discussion except kims above suggested link or any snippet or example on forum.

 

@kims

thanks for ur reply

yes i have already seen that thread. Using that i am trying to implement it but couldnt able to make it and stuck in registring the hotspotclient to device.

 

i have some question:

1. Is it possible to scan available wifi networks from third party application using Hotspot package or not.

2. Is it scans only saved wifi access points on device and list it OR it also scans unsaved access point i.e available wifi networks in surrounding.

3. Is it also possible to connect and set it to device from the list of scanned networks through application.

4. Is there any sample example are available which can help.

 

If you have implemented this or u have any example or snippet, possible can u please share it. It will be very helpful.

 

Thanks,

 

Please use plain text.
Contributor
kims
Posts: 10
Registered: ‎05-31-2010
My Device: Bold
My Carrier: vodafone

Re: How to scan for available networks for device from application?

Hi,

 

1. Is it possible to scan available wifi networks from third party application using Hotspot package or not.

       Yes Possible. and you can connect to required Hotspots listed. Only constrant is it should be open (No Security). Security enabled netwroks are scanned but there are noAPI's to make a connection to these networks.

 

2. Is it scans only saved wifi access points on device and list it OR it also scans unsaved access point i.e available wifi networks in surrounding.

 

Scans all the Wi-Fi.

 

3. Is it also possible to connect and set it to device from the list of scanned networks through application.

 

yes, only Open netwroks, you can connect.

 

 

4. Is there any sample example are available which can help.

 

there are No sample given in JDE/Eclipse.Below is code snippet which may be helpful

 


public class HotspotCredentialsAgentEnabler extends HotspotCredentialsAgent {
    
    private String _userName;
    private String _password;
    private int _crAgent_Preference;
    private Log crAgent_Log;
    
    
    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 String clientName = "";
    private StringBuffer wLanInfoBuff;
    private int count_WAF_WLAN;
    private WLANInfo.WLANAPInfo wLanInfo;
    private int _supportednetworkType;
    
     
    public HotspotClientEnabler(HotspotCredentialsAgent hotspotCrAgent, HotSpotAuthAgentEnabler hotSpotAuthAgent, int supportednetworkTypes) {

        super(hotspotCrAgent, hotSpotAuthAgent, supportednetworkTypes);
        
    }
    public String getClientName() {      
        return "Any Name";      
    }
    public  HotspotInfo[] getSupportedNetworks(WLANInfo.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
        return openCatHotspotInfo; //return only open networks        
    }
    

    

    public void getHotSpotInfo(WLANInfo.WLANAPInfo wLanInfo) {
        
        hotspotClientLog.addlog("HotspotClient class************getHotSpotInfo()");
        //count_WAF_WLAN = RadioInfo.WAF_WLAN;
        wLanInfoBuff = new StringBuffer();
        String ssid = "";
        if(wLanInfo != null) {
            clientName = wLanInfo.getProfileName();
            wLanInfoBuff.append("APChannel*****"+wLanInfo.getAPChannel());
            wLanInfoBuff.append("**BSSID*****"+wLanInfo.getBSSID());
            wLanInfoBuff.append("**DataRate*****"+wLanInfo.getDataRate());
            wLanInfoBuff.append("**Profile Name*****"+wLanInfo.getProfileName());
            wLanInfoBuff.append("**RadioBand*****"+wLanInfo.getRadioBand());
            wLanInfoBuff.append("**SecurityCategory*****"+wLanInfo.getSecurityCategory());
            wLanInfoBuff.append("**SignalLevel*****"+wLanInfo.getSignalLevel());
            ssid = wLanInfo.getSSID();
            wLanInfoBuff.append("**SSID*****"+ssid.toString());    
            hotspotClientLog.addlog("HotspotClient class************getHotSpotInfo()"+wLanInfoBuff.toString());            
        }
        
        
    }
    
    
}

 

 

 

public class HotSpotAuthAgentEnabler extends HotspotAuthenticationAgent {
    
    private String sessionStateLbl="";
    private int _status;
    private String _authStatusMessage;
    private int _applicationCode;
    private Log authAgent_Log;
    private WIFiConnectionManager _wifiManager;
    
    public HotSpotAuthAgentEnabler(WIFiConnectionManager wifiConnMgr) {
       
        _wifiManager = wifiConnMgr;
        updateStatusCustom();
    }
    
    public void updateStatusCustom() {
        
        this.addListener(_wifiManager);
        _status = _wifiManager.getStatus();
        _authStatusMessage = _wifiManager.getAuthStatusMessage();
        _applicationCode = _wifiManager.getApplicationCode();
        this.notifyListeners(getAuthenticationStatusEvent());
    }

    public void login(HotspotInfo hotspot) {
       
    }
    public void logout(HotspotInfo hotspot) {
       
    }
    public void cancelLogin(HotspotInfo hotspot) {
       
    }
    public int getSessionState() {
      
        int sessionState = this.getSessionState();
        
        switch(sessionState){
        
            case HotspotAuthenticationAgent.STATE_CANCELLING_LOGIN:
                sessionStateLbl = "cancelling login";
                break;
            case HotspotAuthenticationAgent.STATE_LOGGED_IN:
                sessionStateLbl = "Logged In";
                break;
            case HotspotAuthenticationAgent.STATE_LOGGED_OUT:
                sessionStateLbl = "logged Out";
                break;
            case HotspotAuthenticationAgent.STATE_LOGGING_IN:
                sessionStateLbl = "Logging In";
                break;
            case HotspotAuthenticationAgent.STATE_LOGGING_OUT:
                sessionStateLbl = "Logging out";
                break;
            case HotspotAuthenticationAgent.STATE_PROBING_NETWORK:
                sessionStateLbl = "Probing Network";
                break;
        
        }
      
        return sessionState;
    }
    
    private AuthenticationStatusEvent getAuthenticationStatusEvent() {
        
        AuthenticationStatusEvent authStateEvent = new AuthenticationStatusEvent(_status, _applicationCode, _authStatusMessage);
        return authStateEvent;
        
    }
    public void probeNetwork(HotspotInfo hotspot){
       
    }
}

 

Now register the Hotspot client with the system

 

try {

            HotspotCredentialsAgentEnabler hotSpotCredentialsAgent = new HotspotCredentialsAgentEnabler();
            hotSpotCredentialsAgent
                    .setCredentialsControlPreference(HotspotCredentialsAgentEnabler.PREFERENCE_DEFAULT);
           

            hotSpotAuthAgentEnabler = new HotSpotAuthAgentEnabler(this);
            hotSpotAuthAgentEnabler.addListener(this);


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

            wifiConnectionLog.addlog("HotspotClientEnabler object created");
            HotspotClientRegistry.add(hotspotClientEnabler,
                    ApplicationDescriptor.currentApplicationDescriptor());
          
            
        } catch (HotspotException hotspotExc) {
            hotspotExc.printStackTrace();
        }

 

 

Thanks,

Kims.

 

 

 

Please use plain text.
Developer
amsiddh
Posts: 142
Registered: ‎06-26-2009
My Device: Not Specified

Re: How to scan for available wifi networks for device from application?

Hi Kims,

 

Thanks for your response. 

 

I am really say thanks you for answering my questions and sharing of code on hotspot api :smileyhappy:. i will try and get back if i need any further help.

 

Thanks,

amsiddh

Please use plain text.
Developer
amsiddh
Posts: 142
Registered: ‎06-26-2009
My Device: Not Specified

Re: How to scan for available wifi networks for device from application?

Hi Kims and All,

 

i was busy with some other project and now I have started implementing for HotspotClient. 

 

Need little more clarification.

 

-when to register the HotspotClient is in application main method or in other class if so then when and where should i call for registration.

-How do i get to connected to my HotspotClient, where as i didn't found any method in hotspotclient package.

 

Thanks

amsiddh

Please use plain text.
mms
Visitor
mms
Posts: 1
Registered: ‎06-28-2010
My Device: Storm 2
My Carrier: Verizon

Re: How to scan for available wifi networks for device from application?

Hi Everyone,

I have followed this thread in hope to learn about using hotspot API to scan Wifi hotspots in the background.

 

Device: Verizon storm 2

 

So far I have basically copied code provided by Kims few posts earlier.

Made some changes to make it compile and run. And I have noticed some things.

 

 

I start running my program with debugger attached and everything runs normally, well too normal.

I can see HoyspotClient.getClientName() gets called several times.

Where is the registration screen?

 

Then I put my test app in background and went to Manage Connection->setup wifi network.

There I see prompt for the registration.

So I 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.

 

This is great! But

 

 - Is there a way to bypass the approval dialog?

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

 

Thank you in advance for the help

 

 

Please use plain text.
Developer
amsiddh
Posts: 142
Registered: ‎06-26-2009
My Device: Not Specified

Re: How to scan for available wifi networks for device from application?

Hi mms,

 

Currently i dont have the device, i am testing this on simulator. As what u have explained similar behaviour i can see on simulator.But can get only array of one network i.e Defalult WLAN Network

 

i am still not clear about the process and flow of the HotspotClient. Hope if someone can put more light on this so it can help us to process further.

 

Thanks

 

 

Please use plain text.