WiFi Tetherinf

FabioG

Active Member
Licensed User
Longtime User
Hi,

I need your help

with this code can not open Tethering Settings
B4X:
   Dim Intent1 As Intent

        Intent1.Initialize(Intent1.ACTION_MAIN,"")
        Intent1.SetComponent("com.android.settings/com.android.settings.TetherSettings")
        StartActivity(Intent1)

but I need to activate the WiFi Tethering automatically without user action.

how can I fix this?

thank you very much
 

FabioG

Active Member
Licensed User
Longtime User
of course,

I need a code to enable WiFi tethering without user action.

Who can help me?

thanks
 
Upvote 0

FabioG

Active Member
Licensed User
Longtime User
it is possible to ?

with this code, but how can I use it with basic4android?


B4X:
private void setWifiTetheringEnabled(boolean enable) {
    WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);

    Method[] methods = wifiManager.getClass().getDeclaredMethods();
    for (Method method : methods) {
        if (method.getName().equals("setWifiApEnabled")) {
            try {
                method.invoke(wifiManager, null, enable);
            } catch (Exception ex) {
            }
            break;
        }
    }
}
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Here:
B4X:
Sub SetWifiApEnabled(Enabled As Boolean)
   Dim r As Reflector
   r.Target = r.GetContext
   r.Target = r.RunMethod2("getSystemService", "wifi", "java.lang.String")
   r.RunMethod4("setWifiApEnabled", Array As Object(Null, Enabled), _
      Array As String("android.net.wifi.WifiConfiguration", "java.lang.boolean"))
End Sub
You should also add this line to the manifest editor:
B4X:
AddPermission(android.permission.CHANGE_WIFI_STATE)

It will not work on all devices.
 
Upvote 0

FabioG

Active Member
Licensed User
Longtime User
Here:
B4X:
Sub SetWifiApEnabled(Enabled As Boolean)
   Dim r As Reflector
   r.Target = r.GetContext
   r.Target = r.RunMethod2("getSystemService", "wifi", "java.lang.String")
   r.RunMethod4("setWifiApEnabled", Array As Object(Null, Enabled), _
      Array As String("android.net.wifi.WifiConfiguration", "java.lang.boolean"))
End Sub
You should also add this line to the manifest editor:
B4X:
AddPermission(android.permission.CHANGE_WIFI_STATE)

It will not work on all devices.

does not work on my Galaxy Nexus

There are other solutions, or other methods?

thanks
 
Upvote 0

FabioG

Active Member
Licensed User
Longtime User
This is a hidden API. It will probably only work on older devices. I'm not familiar with any other way.

Erel,

with this code I open the general settings for Tethering

B4X:
    Dim Intent1 As Intent

    Intent1.Initialize(Intent1.ACTION_MAIN,"")
    Intent1.SetComponent("com.android.settings/com.android.settings.TetherSettings")
    StartActivity(Intent1)

how can I open the configuration Dialog of WiFi HotSpot?
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
how can I open the configuration Dialog of WiFi HotSpot?

Like I said on my previous post, the device MUST support it, for example, if I ran that code on my EVO I can see and get the WiFi Tether Settings and activate them, if I ran the same code on a Nexus 7 tab, I open the screen but the screen is BLANK, on a Galaxy tab shows the settings and able to change the settings, on other devices you might even see a blank screen like I mentioned or just disabled buttons.

Like Erel also mentioned, it's a hidden API which is usually managed by the telcom provider.
 
Upvote 0

FabioG

Active Member
Licensed User
Longtime User
Like I said on my previous post, the device MUST support it, for example, if I ran that code on my EVO I can see and get the WiFi Tether Settings and activate them, if I ran the same code on a Nexus 7 tab, I open the screen but the screen is BLANK, on a Galaxy tab shows the settings and able to change the settings, on other devices you might even see a blank screen like I mentioned or just disabled buttons.

Like Erel also mentioned, it's a hidden API which is usually managed by the telcom provider.

I know that already, in fact I have already implemented all the controls.

I need to figure out how to open the CONFIGURATION Dialog of WiFi HotSpot.
 
Upvote 0

FabioG

Active Member
Licensed User
Longtime User
Here:
B4X:
Sub SetWifiApEnabled(Enabled As Boolean)
   Dim r As Reflector
   r.Target = r.GetContext
   r.Target = r.RunMethod2("getSystemService", "wifi", "java.lang.String")
   r.RunMethod4("setWifiApEnabled", Array As Object(Null, Enabled), _
      Array As String("android.net.wifi.WifiConfiguration", "java.lang.boolean"))
End Sub
You should also add this line to the manifest editor:
B4X:
AddPermission(android.permission.CHANGE_WIFI_STATE)

It will not work on all devices.



Erel,

how can I use Reflector to change the SSID and Key?

I read this but I do not understand: (
WifiConfiguration | Android Developers
thanks
 
Upvote 0

FabioG

Active Member
Licensed User
Longtime User
It will be difficult to do it with Reflector. You will need to write a library for that (check ABWifi first).

ABWifi if I'm not mistaken the opportunity to read the information and do not write.

thanks anyway
 
Upvote 0
Top