Android Question Can someone help me get started with MLWifi

jimseng

Active Member
Licensed User
Longtime User
Hello. I'm just trying to get started with the simple wifi example. I can't see what I have got wrong with this simple example of just scanning wifi networks. The Scan_ScanDone event doesn't happen. What have I missed?
B4X:
Sub Class_Globals
    Dim wifi As MLwifi
    Dim scan As MLScan
    Private Root As B4XView
    Private xui As XUI
    Private btnDiconnect As Button
    Private btnScan As Button
    Private wifilist As List
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    wifi.EnableWifi(True)
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Sub Scan_ScanDone(Results() As String, Count As Int)
    Dim tmp As String
    For i = 0 To Count - 1
        tmp = Results(i).Replace(",","    ")
        wifilist.Add(tmp)
        Next
End Sub

Private Sub btnScan_Click
    scan.startScan("Scan")
  
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
Upload a small project showing the problem
 
Upvote 0

jimseng

Active Member
Licensed User
Longtime User
Hi. That is the entire code at the moment. I was just getting started with WiFi and copying the example I thought the scan_done and b would get fired. I can upload a project when I get home but it doesn't contain any more than this. I think I have missed a crucial bit.
 
Upvote 0

jkhazraji

Active Member
Licensed User
Longtime User
check permissions:
B4X:
android.permission.ACCESS_NETWORK_STATE
android.permission.ACCESS_WIFI_STATE
android.permission.CHANGE_WIFI_STATE
android.permission.ACCESS_FINE_LOCATION
android.permission.INTERNET
 
Upvote 0

jimseng

Active Member
Licensed User
Longtime User
Presumably I do this in the manifest editor? Having done so I still have no luck.
My project attached as a zip.

The text file included in the library states:

Note: This library adds 3 permissions to your app automatically. Those permissions are:

android.permission.ACCESS_NETWORK_STATE

android.permission.ACCESS_WIFI_STATE

android.permission.CHANGE_WIFI_STATE
 

Attachments

  • GoProGo.zip
    10.1 KB · Views: 57
Last edited:
Upvote 0

jimseng

Active Member
Licensed User
Longtime User
So call me controversial but I'm not sure it is possible with a pixel 8 pro. Perhaps the permissions don't work any more because none of the examples work and aren't able to turn on wifi. If anybody has a working up to date example I would love to see it.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
deprecated in API level 29. Starting with Build.VERSION_CODES#Q, applications are not allowed to enable/disable Wi-Fi.
 
Upvote 0

jimseng

Active Member
Licensed User
Longtime User
But are we able to change/connect to different wifi networks? I have had no success with MLwifi library. Is there a different library I should be using or is it no longer possible to do any wifi stuff?
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
wifi scanning has been restricted (for the usual reasons) and in a number of unpleasant ways, and
google has stated that, soon, users will not be able to scan at all.

turning on wifi, scanning and connecting has already been done. why waste your time trying to
duplicate what can no longer be done from userland? especially given the device you have.

go find a cheap android 4 device and do your "warwalking" like it was 1999 and every home access
point was open.
 

Attachments

  • startscan.png
    startscan.png
    18.1 KB · Views: 61
Last edited:
Upvote 0

jimseng

Active Member
Licensed User
Longtime User
So forgetting scanning, is it not possible to programmatically connect to a different, known wifi point and then back again? In other words, is any form of wifi connection withing B4x no longer possible?
What's warwalking?
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
you keep changing the goal. it is possible to connect programmatically to an access point. the library you are using may be able to handle it. you need for wifi to be enabled already, and you need all the permissions in your manifest. for the moment, scanning may work. in any case, if you are able to address the access point directly with the library, you should be able to connect. the library you are using, although updated since originally written, may be dated. the problems you are encountering have nothing to do with b4x; they relate to restrictions imposed by google. whatever is legal in android can be handled by b4x. if you can operate within those restrictions, the library may work just fine. if not, you may need to look for a different library. static libraries may need to be updated to keep up with google's changes. in some cases, the library might be ok, but the app using it might need to conform to the changes.

as for warwalking (or, for the more mobile, wardriving), google it.
 
Upvote 0
Top