Android Tutorial B4A-Bridge over wifi without a local network

Starting from B4A v5.0, B4A-Bridge over Bluetooth is no longer available. You can use B4A-Bridge over wifi or USB debug mode to connect the IDE to a device.

By creating a mobile hotspot you can easily connect to a device with B4A-Bridge even if there is no local network.

The steps are:
1. Start a mobile hotspot on the device.
2. Connect the computer to the mobile hotspot.
3. Start B4A-Bridge. It will show a message saying: "Not connected to wireless network". Ignore it.
4. Set the following IP address in the IDE: 192.168.43.1 (this is the default ip address of devices serving as a mobile hotspot).

upload_2015-6-15_9-27-9.png


Notes


- This will work even if there is no sim card in the device.
- If there is a sim card then it is recommended to turn airplane mode on as otherwise the computer will use the device mobile network provider to connect to the internet. This may result in large bandwidth consumption.
 

Troberg

Well-Known Member
Licensed User
Longtime User
This assumes that you can select which network the computer connects to, and that you can disconnect from the network it is currently connected to (which isn't accessible by the "foreign device" phone).
 

Dave O

Well-Known Member
Licensed User
Longtime User
If there is a sim card then it is recommended to turn airplane mode on as otherwise the computer will use the device mobile network provider to connect to the internet. This may result in large bandwidth consumption.

I think you mean "turn off mobile data", because Airplane Mode turns off mobile AND WiFi, which would cut off the PC.
 

zsugar

Member
Licensed User
Longtime User
Hi, tried to establishe a wireless connection as you described, but I obtained only this message:
 

Attachments

  • Untitled.png
    Untitled.png
    130.1 KB · Views: 1,258

zsugar

Member
Licensed User
Longtime User
My device is a Nexus 5, so I suppose IP address is 192.168.43.1. I noticed that when I enable Hot spot WIFI is turn-off automatically.
Is possible a problem ?

Thanks
 

timwil

Active Member
Licensed User
Longtime User
WiFi is turned off automatically because the WiFi on the phone is now being used to serve your PC
 

KnipsFips

New Member
Licensed User
Longtime User

Hi,

I just upgraded to B4a V5 and cannot connect to B4A-Bridge anymore.
It used to pop up a message that it couldn't ping my android device but nevertheless it connected fine.
After the upgrade to B4A V5 it still says that it cannot ping the device but now it is not connecting anymore.

I am running V2.09 and wanted to download the apk from your given link but the link points to V2.09.
Could you please update your link to B4A-Bridge.apk to the current version (2.12)?

thanks
 

agraham

Expert
Licensed User
Longtime User
Since Android 10 and later 192.168.43.1 is no longer the default IP address of devices serving as a mobile hotspot. Instead it is randomised, seemingly like 192.168.abc.def, so if you want to use B4ABridge via this local hotspot you need to know the actual IP address to use instead of assuming 192.168.43.1.

The following Java getIpAddress() method will return a string of newline separated IP addresses for the device. When normally connected to WiFi it will have just a single IP address but when acting as a hotspot it will have two. One that is the connection to the WiFi network and one that is its address on the hotspot network. If it is not connected to a local network but is acting as a hotspot it will have just its own hotspot address which as Erel notes above B4ABridge will not see so you can use this code to find it.

B4X:
Sub Button1_Click
    Dim jo As JavaObject
    jo.InitializeContext
    MsgboxAsync(jo.RunMethod("getIpAddress", Null), "IP Adresses")
End Sub

#if java

import java.net.NetworkInterface;
import java.util.Enumeration;
import java.net.InetAddress;

public String getIpAddress() {
     String ip = "";
    try {
        Enumeration<NetworkInterface> enumNetworkInterfaces = NetworkInterface.getNetworkInterfaces();
        while (enumNetworkInterfaces.hasMoreElements()) {
            NetworkInterface networkInterface = enumNetworkInterfaces.nextElement();
            Enumeration<InetAddress> enumInetAddress = networkInterface.getInetAddresses();
            while (enumInetAddress.hasMoreElements()) {
                InetAddress inetAddress = enumInetAddress.nextElement();
                if (inetAddress.isSiteLocalAddress()) {
                    ip += inetAddress.getHostAddress() + "\n";
                }
            }
        }
    } catch (Exception e) {
        ip += "Something Wrong! " + e.toString() + "\n";
    }
    return ip;
}
#End If
 

bparent

Member
Licensed User
Longtime User
Since Android 10 and later 192.168.43.1 is no longer the default IP address of devices serving as a mobile hotspot. Instead it is randomised, seemingly like 192.168.abc.def, so if you want to use B4ABridge via this local hotspot you need to know the actual IP address to use instead of assuming 192.168.43.1.

The following Java getIpAddress() method will return a string of newline separated IP addresses for the device. When normally connected to WiFi it will have just a single IP address but when acting as a hotspot it will have two. One that is the connection to the WiFi network and one that is its address on the hotspot network. If it is not connected to a local network but is acting as a hotspot it will have just its own hotspot address which as Erel notes above B4ABridge will not see so you can use this code to find it.

B4X:
Sub Button1_Click
    Dim jo As JavaObject
    jo.InitializeContext
    MsgboxAsync(jo.RunMethod("getIpAddress", Null), "IP Adresses")
End Sub

#if java

import java.net.NetworkInterface;
import java.util.Enumeration;
import java.net.InetAddress;

public String getIpAddress() {
     String ip = "";
    try {
        Enumeration<NetworkInterface> enumNetworkInterfaces = NetworkInterface.getNetworkInterfaces();
        while (enumNetworkInterfaces.hasMoreElements()) {
            NetworkInterface networkInterface = enumNetworkInterfaces.nextElement();
            Enumeration<InetAddress> enumInetAddress = networkInterface.getInetAddresses();
            while (enumInetAddress.hasMoreElements()) {
                InetAddress inetAddress = enumInetAddress.nextElement();
                if (inetAddress.isSiteLocalAddress()) {
                    ip += inetAddress.getHostAddress() + "\n";
                }
            }
        }
    } catch (Exception e) {
        ip += "Something Wrong! " + e.toString() + "\n";
    }
    return ip;
}
#End If

I may be doing something wrong. I have included the javaobject library, but I still get the following error:
java.lang.RuntimeException: Method: getIpAddress not found in: b4a.example.main

Any ideas?
 

bparent

Member
Licensed User
Longtime User
I've copied and pasted the above code into my test app and it works for me.

Thanks. I downloaded your B4A file and it works for me too. For some reason, when I use the default B4X template and put the same code in I get the error. Maybe I have some invisible characters in the copy and pasted code?
 

tagwato

Member
Licensed User
Longtime User
To find the IP address to be set in the IDE, after connecting your computer to the mobile HotSpot (step 4 of the first post):
- open a CMD prompt
- type "ipconfig" and hit Enter
- copy the IP addres under "Default Gateway"
 
Last edited:
Top