B4A Library Hotspot - share your wifi

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

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

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

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.

    Private Button2 As Button
    Private Button1 As Button
    Dim a As Hotspotlib
    Private Button3 As Button
    Private CheckBox1 As CheckBox
    Private txtmatkhau As EditText
    Private txtten As EditText
    Private RadioButton2 As RadioButton
    Private RadioButton1 As RadioButton
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("1")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
        a.tat
    ToastMessageShow("Starting turn off wifi hotspot and exit, please wait.......",True)
    Activity.Finish
End Sub
Sub Button2_Click
    a.tat
If RadioButton2.Checked=True Then
    a.batdau(txtten.text,True,txtmatkhau.Text)
    ToastMessageShow("Starting turn on wifi hotspot " & txtten.Text & " with password " & txtmatkhau.Text & ", please wait.......",True)
    Else
    ToastMessageShow("Starting turn on wifi hotspot " & txtten.Text & " without password, please wait.......",True)
    a.batdau(txtten.text,False,"")
    End If
End Sub
Sub Button3_Click
    a.tat
    ToastMessageShow("Starting turn off wifi hotspot, please wait.......",True)
   
End Sub
Sub CheckBox1_CheckedChange(Checked As Boolean)
    If CheckBox1.Checked=True Then
    txtmatkhau.PasswordMode=False
    Else
    txtmatkhau.PasswordMode=True
    End If
End Sub


With full project and library

source : http://basic4ppc.com/android/forum/threads/hotspot-in-b4a-is-it-impossible.41704/
and http://www.b4x.com/android/forum/threads/wifi-tetherinf.27048/#post-156666
 

Attachments

  • freewifi.zip
    65.9 KB · Views: 795
  • Hotspotlib.zip
    3.2 KB · Views: 785

Beja

Expert
Licensed User
Longtime User
Hi
thanks for the lib and project.
I repeat Rick's question:
1- Can I make an http server for others to login then I can either keep them inside my server or pass them to the Internet.
2- Can I setup a web server in my Android device without being connected to any Wi-Fi?
 

Croïd

Active Member
Licensed User
Longtime User
screen.png

tuhatinhvn what should i do?
 

Carlos M. Cruz Malerva

Member
Licensed User
Longtime User
Hello tuhatinhvn, it's a great lib and work with 4.x.x, but not work en 5.x, this is the error.

Error occurred on line: 140 (Main)
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.htsoft.hotspotlib.Hotspotlib.tat(Hotspotlib.java:38)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:680)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:308)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:4756)
at android.view.View$PerformClick.run(View.java:19749)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
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:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.SecurityException: ConnectivityService: Neither user 10046 nor current process has android.permission.CHANGE_NETWORK_STATE.
at android.os.Parcel.readException(Parcel.java:1540)
at android.os.Parcel.readException(Parcel.java:1493)
at android.net.wifi.IWifiManager$Stub$Proxy.setWifiApEnabled(IWifiManager.java:1261)
at android.net.wifi.WifiManager.setWifiApEnabled(WifiManager.java:1380)
... 24 more


thanks a lot.
 

camolas

Member
Licensed User
Longtime User
Hi,

I want to use Hotspotlib in a service that works in background but i cant use "Dim a As Hotspotlib" in service "Sub Process_Globals" because is to be used in activity "Sub Globals" how can a passe this problem?

Thanks
 

janderkan

Well-Known Member
Licensed User
Longtime User
Hi

Is it possible to have you translate the following words:
batdau
datmatkhau
matkhau

also the getWifiApstate returns 1 and 3, can you tell the meaning of this and is there a 2?

Thank you
 

janderkan

Well-Known Member
Licensed User
Longtime User
AddPermission(android.permission.CHANGE_WIFI_STATE)
AddPermission(android.permission.ACCESS_WIFI_STATE)


Sub SetWifiApEnabled(Enabled As Boolean, ApName As String)
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod2("getSystemService", "wifi", "java.lang.String")
Dim wc As JavaObject
wc.InitializeNewInstance("android.net.wifi.WifiConfiguration", Null)
wc.SetField("SSID", ApName)
r.RunMethod4("setWifiApEnabled", Array As Object(wc, Enabled), Array As String("android.net.wifi.WifiConfiguration", "java.lang.boolean"))
End Sub


'State
'0 = WIFI_AP_STATE_DISABLING
'1 = WIFI_AP_STATE_DISABLED
'2 = WIFI_AP_STATE_ENABLING
'3 = WIFI_AP_STATE_ENABLED
Sub GetWifiApState() As Int
Dim Res As Int = 0
Dim r As Reflector
Try
r.Target = r.GetContext
r.Target = r.RunMethod2("getSystemService", "wifi", "java.lang.String")
Res = r.RunMethod("getWifiApState")
If Res >= 10 Then Res = Res - 10
Catch
Res = 0
Log(LastException)
End Try
Return Res
End Sub
 

Declan

Well-Known Member
Licensed User
Longtime User
Is it possible to set the channel number?
I am using a ESP8266 WiFi module that allows setting channels 0 through 4.
My Android device always defaults to channel 6.
 
Top