B4A Library Android Wifi Hotspot Manager

It wraps this Github project. It prints the connected clients to the B4A log. We can panel beat it a bit if I know what info you would like to have returned to the B4A project. I have tested it between my tablet (client) and cell phone (hotspot) and it seems to work 100%.

Note the permissions added to the B4A manifest file
B4X:
AddPermission(android.permission.CHANGE_WIFI_STATE)
AddPermission(android.permission.ACCESS_WIFI_STATE)
AddPermission(android.permission.INTERNET)

Sample Code:

B4X:
#Region  Project Attributes
    #ApplicationLabel: HotSpot
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
 
    Dim t As Timer

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
 
    Dim hs As HotSpot

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
 
    t.Initialize("t", 2000)
 
    hs.Initialize("")

End Sub

Sub Activity_Resume
 
t.Enabled = True

End Sub

Sub Activity_Pause (UserClosed As Boolean)
 
    t.Enabled = False

End Sub

Sub t_tick
 
 
hs.scan
 
End Sub

You can download and test any posting of mine in this thread but if you want to use it then you need to
 

Attachments

  • b4aHotSpot.zip
    6.7 KB · Views: 694
  • HotSpotLibFiles.zip
    7 KB · Views: 721
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
If I comment out that line, the hotspot is not enable (Is Wifi AP enabled = false).
Did you comment this line....?

'hs.AccessPointNameAndPassword("Hotspot Name", "")

I have just tested it and it works
 

susu

Well-Known Member
Licensed User
Longtime User
I tested on 2 devices:

Device 1: I tried your sample code with hs.AccessPointNameAndPassword("Hotspot Name", "Password"). It turn on hotspot with name and password. After that, I remove / comment out hs.AccessPointNameAndPassword("Hotspot Name", "Password"). It still turn on hotspot with the same name and password (it remember the last time). I need to manually change hotspot to Open.

Device 2: Never use hotspot. I tried sample code without hs.AccessPointNameAndPassword("Hotspot Name", "Password"). It can not turn on hotspot.

Thank you Johan.
 

deantangNYP

Active Member
Licensed User
Longtime User
is this library able to do the following? Thanks
- List devices connected , the list currently shows "wlan0" only regardless of devices type.
- show the wifi hotspot name
 
Last edited:

T201016

Active Member
Licensed User
Longtime User
Hi, Johan!
Testing your library I met the following event.
Well, while tethering or access point is active (Wi-Fi Hotspot is on)
the WiFi icon is crossed out (in other words, inactive?). Despite this, the AP works without a problem.

Can this icon WiFi (see file 2018-04-11_1.png) somehow activate?

Besides, the library is well made.
It is a pity that it is not free, but for personal use :)

Regards.
 

Attachments

  • 2018-04-11_1.png
    2018-04-11_1.png
    207.3 KB · Views: 235
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
Hi, Johan!
Testing your library I met the following event.
Well, while tethering or access point is active (Wi-Fi Hotspot is on)
the WiFi icon is crossed out (in other words, inactive?). Despite this, the AP works without a problem.

Can this icon (see file 2018-04-11_1.png) somehow activate?

Besides, the library is well made.
It is a pity that it is not free, but for personal use :)

Regards.
Feel free to use it whichever what you want.....;)
 
Hi Johan,
I'm trying your lib which works great on older phones, instead on newer ones I get the following exception after calling the hs.scan:

java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io.BufferedReader.close()' on a null object reference

Also enclosing the hs.scan in a try/catch, it makes the app to crash.

I'm using B4A 11.50 with jdk-11.0.1

Thanks
 

Johan Schoeman

Expert
Licensed User
Longtime User
If I comment out that line, the hotspot is not enable (Is Wifi AP enabled = false).
It is an old library from 7 years ago. I guess there must be something far more recent in the forum that you can use
 
Hi Johan,
I'm trying your lib which works great on older phones, instead on newer ones I get the following exception after calling the hs.scan:

java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io.BufferedReader.close()' on a null object reference

Also enclosing the hs.scan in a try/catch, it makes the app to crash.

I'm using B4A 11.50 with jdk-11.0.1

Thanks

I found the answer to my question: starting from Android 10 the "/proc/net/arp" is not more accessible.

Also found that using "ip neigh show" as a workaround it not working on Android 11 :confused:
 
Top