B4A Library Simple WIFI library Updated V. 3.07 09-05-2018

DonManfred

Expert
Licensed User
Longtime User

Michael Wenning

Member
Licensed User
Longtime User
Hello Manfred,
I have reinstalled the sdk with b4a sdk manager.
Now the android.jar path is: C:\Android\platforms\android-27\android.jar
I have removed the app from mobile.
I have restart the samsung mobile.
I have installed in debug mode with b4a bridge.
Nothing changed:

Logger verbunden mit: samsung SM-A320FL
--------- beginning of main
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (activity_permissionresult)
running waiting messages (1)
** Activity (main) Resume **
*** Service (icon) Create ***
** Service (icon) Start **
Wifi scan started!
scan done 0
scan done 0
scan done 0
scan done 0
** Activity (main) Pause, UserClosed = true **
** Service (icon) Destroy **
Wifi scan stopped!

Perhaps is a good idea with the teamviewer.
When have you time for this issue? Perhaps on monday?

Best regards
Michael
 

Michael Wenning

Member
Licensed User
Longtime User
I have found solution:
On 8.0 android devices you must have "Location enabled" in order for wifimanager to work.
Now it works:

Logger verbunden mit: samsung SM-A320FL
--------- beginning of main
scan done 0
scan done 0
scan done 0
scan done 0
** Activity (main) Pause, UserClosed = true **
** Service (icon) Destroy **
Wifi scan stopped!
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (icon) Create ***
** Service (icon) Start **
Wifi scan started!
scan done 8
scan done 8
scan done 9
scan done 10
** Activity (main) Pause, UserClosed = true **
** Service (icon) Destroy **
Wifi scan stopped!

Best regards
Michael
 

bgsoft

Well-Known Member
Licensed User
Longtime User
Hi:

I have implemented new methods and events, above is the new version 3.04 and 3.05

regards
 

Paulo Rosa

Member
Licensed User
Hi @bgsoft,

This is a fantastic library, thanks a lot for the nice work. I'm working on a project that uses MLWiFi (Simple Wifi Library) and the library has been very useful.

Could I make a feature request here?

Since Android 6.0+ requires location access to scanning Wi-Fi, it would be very nice if the required permissions were added to the library:

android.permission.ACCESS_FINE_LOCATION
android.permission.ACCESS_COARSE_LOCATION


Regards,
 

bgsoft

Well-Known Member
Licensed User
Longtime User

Hi Paulo:

These two permissions are already added, from version 3.04.

Regards
 

bgsoft

Well-Known Member
Licensed User
Longtime User
Hi:


Corrected compatibility issues with API level <23 new version 3.06

regards
 

Paulo Rosa

Member
Licensed User
Hi @bgsoft,

Although android.permission.ACCESS_FINE_LOCATION and android.permission.ACCESS_COARSE_LOCATION are indeed included in version 3.05, my app still was getting an empty results array. Only after I included runtime permission code in my app, I could get the correct results array.

Regards,
 

Paulo Rosa

Member
Licensed User
Forgot to say: my phone has Android 7.0.
 

bgsoft

Well-Known Member
Licensed User
Longtime User
Hi:


Corrected compatibility issues with API level <21 new version 3.07

regards
 

Michael Wenning

Member
Licensed User
Longtime User
Thank's for that great libary. I use this and it works very good.

After start connection to Access Point
i ask for sucsessfull connection:


B4X:
Private Sub ConnectToAP ( strApName As String, strApPassWort As String) As ResumableSub
    Dim Mk_IstSavedAp As Boolean
 
    'Dim strPassWort As String
    Dim Mk_Fehler As Boolean
    Dim Mk_ErfolgreichConnected As Boolean
 
    Dim z As Int
 
    If strApName.Length > 0 Then
        If Starter.wifi.isSavedWifiAP(strApName) Then
            Mk_IstSavedAp = True
         
            Log ( strApName & " ist ein auf dem Handy gespeicherter Access Point!")
        Else
            Mk_IstSavedAp = False
            Log ( strApName & " ist kein ein auf dem Handy gespeicherter Access Point!")
        End If
    End If
 
 
    If Mk_IstSavedAp = True Then
        Mk_ErfolgreichConnected = Starter.wifi.connectWifiAP(strApName)
        Log ("Mit zuvor gespeicherten Access Point " & strApName & " erfogreich connected: " &  Mk_ErfolgreichConnected)
    Else
     
        ' 2 ==> WPA 2
        Starter.wifi.saveWifiAP(strApName, 2, strApPassWort, False)
     
        Sleep(500)
     
        Mk_ErfolgreichConnected = Starter.wifi.connectWifiAP(strApName)
     
 
    End If
 
    Mk_Fehler = False
 
 
    z = 0
             
    Do Until Starter.wifi.WifiSSID = strApName
        z = z + 1
        Sleep(10)
        If z > mgl_intConnectVersuche Then
            Log ("Connection nach " &  strApName & " nicht geschafft!")
            ToastMessageShow("Connection nach " &  strApName & " nicht geschafft!" ,True)
            Mk_Fehler = True
            Exit
        End If
    Loop

    Log ("Wartezeit [mSek] für Connect Versuche zu " & strApName & ": " & (z*10))
     
    If Mk_Fehler = False Then
        Return True
    Else
        Return False
    End If
 
 
End Sub

After establishing the connection to the access point I ask if it was successful. After 30 to 2500 milliseconds I get the positive feedback. If I connect directly to a server, I often get an error message. The server is unreachable...
If I adjust the scenario in my test app and wait until the Wifi symbol is visible in the notification area, it always works. I have now alternatively worked with timers and checked the presence of the stable access point. This is very inefficient. Is there a more elegant/effective way? Maybe an intent / broadcast message?
 
Last edited:

Marcob

Member
Licensed User
Longtime User

I guess the sentence "the permissions are included in version 3.05" means here that you don't need to add them with manifest editor but of course your app still needs the user to grant them at runtime.
 

Paulo Rosa

Member
Licensed User
I guess the sentence "the permissions are included in version 3.05" means here that you don't need to add them with manifest editor but of course your app still needs the user to grant them at runtime.
Thanks. I didn't know much about runtime permissions... until know.
 

Paulo Rosa

Member
Licensed User
Hi @bgsoft,

Regarding the method updateWiFiList,

According to the documentation, "This method returns a string array containing the access points from the most recent scan, including background scans done automatically by the Android WifiManager."

I would like to suggest that you include a (possibly optional) parameter which when true make updateWiFiList force the Android WiFiManager to do a new Wi-Fi AP scan. The reason for this request is that in some situations, the AP list can be eventually outdated as the phone is moved around in an environment with several APs (like my house which has four APs...).

I'm aware that recent Android versions are gradually limiting the number of times an app can force the WiFiManager to do a AP scan. But that's not a problem, for my app would not call repeatedly for a forced scan and that would be done only in foreground.

Regards,
 

Paulo Rosa

Member
Licensed User
Hi @Michael Wenning,

You could define a dynamic Broadcast Receiver and listen to "android.net.conn.CONNECTIVITY_CHANGE".

BroadcastReceiver library allows you to implement that on a straightforward way. After connecting to the desired AP, you could use the BroadcastReceiver event function to check the state of MlWiFi.isWiFiConnected.

Regards and good luck!
 

SimonInCanada

Member
Licensed User

V-3.07 by bgsoft

Corrected compatibility issues with API level <21
______________________________________________________________________

V-3.06 by bgsoft

Corrected compatibility issues with API level <23

1) I am forced to develop for some I.S. Phones which have Android 4.4.2 (and my app was developed using 3.03 of this library. Not all of the library worked for <Android 5. Do these changes mean that all the features in the library will now work or do they just apply to ScanDone?

2) Does anybody know of a simple example using ScanDone as I tried to use it instead of reflection but I am struggling with it?

Thanks in advance, Simon
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…