B4A Library Simple WIFI library

Discussion in 'Additional libraries, classes and official updates' started by HotShoe, Mar 8, 2014.

  1. HotShoe

    HotShoe Well-Known Member Licensed User

    Oh, I see what you mean, yes that can be done easily in MLScan. I'll add it in the next update. BTW, you can check the MLScan.wifis array at any time, but it will not update without explicitly doing a new scan right now.

    --- Jem
    FrankBerra likes this.
  2. cooperlegend

    cooperlegend Active Member Licensed User

    I am getting a NullPointerException when using connectToAP :(
  3. Peter Simpson

    Peter Simpson Expert Licensed User

    This library has just gotten better @HotShoe, thank you...
  4. HotShoe

    HotShoe Well-Known Member Licensed User

    Thanks John, I have updated the library and have also fixed the connectToAP method again. I missed a set of required quote marks on a wifimanager call.

    A new version 2.11 is now available (as soon as I finish this reply), in the first post. Only MLscan is changed as follows.

    This version no longer needs a timer or any other means of ensuring that the wifi scan list is ready. It now fires an event when the list is ready. The event looks like this assuming your scan event is called Scan :

    Sub Scan_ScanDone(Results() As String, Count As Int)

    Results is the string array as before, and Count is the number of results in the array. The wifis array is still available as well and is updated automatically.

    The StartScan method has changed and now requires an event name to be passed. It also checks to see that wifi is enabled and enables it if it is not. Through a bit of magic, I was able to squeeze another 70% speed increase in the scan results time, so the speed is finally where I am comfortable with the library as a whole. It felt a bit clunky before, but my custom event was not working until today. Scans are virtually instant now.

    Also, the getWifiList is now gone (I'm sorry, I promise I will stop breaking your code), and is replaced with updateWifiList. WifiList is no longer needed in this version since updates are done in the new event. A call to updateWifiList updates the scan results each time it is called, so you can set up a timer if you wish to do live updates of a listview for example as new AP's appear. You only need to call StartScan("eventname") the first time a scan is run, the same as you would use Initialize for any other library class. I was tempted to rename it to Initialize, but I can already here the pitchfoks rattling for all of the changes up to now. :)

    If you see any more problems, let me know as always, and thanks for putting up with the changes.

    --- Jem
  5. praktikant

    praktikant Member Licensed User

    hallo,thank you @@HotShoe , for this Lib
    i have now a question.

    when a wifi ist connected,
    i scan wifi netzwerk again
    I noticed that, signal strength of this connected wifi dont changes with different distances
    how can i test this signal strength of the connected wifi with different distances???
    Can you give me an example of that?

    Sub wifi_Tick
    End Sub
    Sub Scan_ScanDone(Results() As String, Count As Int)
    Dim tmp As String
    For i = 0 To Count - 1
        tmp = Results(i).Replace(
    ",","    ")
    End Sub
    Last edited: May 29, 2015
  6. HotShoe

    HotShoe Well-Known Member Licensed User

    You can set a timer to repeat the update every minute or other length of time.

    'Dim a timer in process_globals named scantime and initialize it in activity_create

    'enable the timer after the initial scan is done
       scantime.Enabled = True

    'create the tick event for the timer to update the scan list
    Sub scantime_Tick
         scantime.Enable = 

         scantime.Enable = 

    End Sub
    Some variation of this should work.

    --- Jem
  7. praktikant

    praktikant Member Licensed User

    Sub Service_Create
    End Sub

    Sub WiFiScanTimer_Tick
    WiFiScanTimer.Enable = 
       WiFiScanTimer.Enable = 
    End sub
    Error compiling programm.
    error description:Unknown member:enable

    i dont know, what happend
    Code dont work.
  8. HotShoe

    HotShoe Well-Known Member Licensed User

    Try the new version attached to the first post. Also look at the new wifitest example to se exactly how to do what you need.

    --- Jem
  9. XorAndOr

    XorAndOr Active Member Licensed User

    Hi, I'm using your library, very useful. I have a question, when I go to connect with an access point in the moment that I enter the password I get the
    MsgBox("Could not connect to" & ssid, "Information")
    , but if I do it from the list of devices your phone is everything ok, where do you think I'm wrong? I also added
    AddPermission (android.permission.WRITE_SETTINGS)
    but I get always the msgbox, thanks
  10. HotShoe

    HotShoe Well-Known Member Licensed User

    hmmm, I don't know. Look through the wifitest project and make sure you are doing the connection the same way.

    --- Jem
  11. XorAndOr

    XorAndOr Active Member Licensed User

    hello, thank you for responding, I am using the example attached in the first post. I noticed that in the list of access points do not see the message "Saved"
    If tmp.Contains("Saved"Then
       ok = scan.connectToAP(cursel)
    I think that's why it does not work, but if I do it with paired device and insert the password from the phone menu, then returning to the example works ok. thanks
  12. jjcc

    jjcc Member Licensed User

    @HotShoe Great lib!
    However, I tried the example project. connectToAP doesn't work with a few phones I tried. I tried to forget a connection within the android setting, then tried the sample code to let the the app saves the password and connect to phone. the result the of connectToAP is OK but it's not really connect to the AP. (the IP shows and call isWifeConnected return false after init)

    Did you have the same issue?
  13. HotShoe

    HotShoe Well-Known Member Licensed User

    I have not seen this, but I will look at it again to see if there is something I missed.


    --- Jem
  14. camolas

    camolas Member Licensed User


    Can some one please present a example using "forgetAP"? and how can i get the "NetId" from my saved wifis list?

    Thanks in advance

  15. jjcc

    jjcc Member Licensed User

    @HotShoe I guess it might be caused by quote string of SSID. There are different versions of SDK, some use quoted string, the others don't.

    Here's the link about the problem

    Do you have time to fix the lib? or if you have already uploaded the code somewhere in github?
    305500 likes this.
  16. HotShoe

    HotShoe Well-Known Member Licensed User

    Sorry I've been away so long.

    Use the listSavedNetworks method. It returns a list of saved networks on your device. the 3rd item in each listing is the network ID. Each element is separated by a comma. Then you can call the forgetAP method based on the SSID and network ID that you want to erase from your device. I will update the wifitest project later and include an example in there.

    I have updated mlwifi to handle both quoted and unquoted SSID strings, so try version 2.13 attached in the 1st post of this thread.

    --- Jem
    jjcc and camolas like this.
  17. jjcc

    jjcc Member Licensed User

  18. omidaghakhani1368

    omidaghakhani1368 Well-Known Member Licensed User

    Thanks for useful library.
    If user connect to internet via gsm,your library can detect it?
  19. HotShoe

    HotShoe Well-Known Member Licensed User

    It can, but that is the only non-wifi related thing that it can do. The rest of the methods are specifically for wifi.

    --- Jem
  20. Mark Hollingworth

    Mark Hollingworth Member Licensed User

    Great Library has been working fine but I seem to have hit a problem and I am not sure whats causing it.

    I have a service which listens for network connection events and then runs code depending on the connection state, it works fine when a wifi connection is found but when the wifi is disconnected I am getting the following error:

    java.lang.RuntimeException: Error receiving broadcast Intent { act=android.net.wifi.SCAN_RESULTS flg=0x4000010 } in wifi.MLwifi$MLWifiScanner$WifiScanReceiver@274d9542
    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:982)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:6837)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
    Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference
    at wifi.MLwifi$MLWifiScanner.checkSSID(MLwifi.java:346)
    at wifi.MLwifi$MLWifiScanner.access$0(MLwifi.java:339)
    at wifi.MLwifi$MLWifiScanner$WifiScanReceiver.onReceive(MLwifi.java:324)
    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:972)

    I have tried various things to resolve it but have been unable to. I am attaching a sample project that is causing the same error and it always happens after calling .StartScan, if I remove that line of code from the service then it doesn't crash.

    Also the .StartScan seems to be continually returning results, is that intended or should it perform one scan then stop?

    Your help is appreciated

    Attached Files:

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice