Android Tutorial B4A-Bridge a new way to connect to your device

Status
Not open for further replies.
There are several options to develop with B4A:
- Android emulator or a VM.
- Connect to a real device in USB debugging mode
- Connect to a real device with B4A-Bridge.

I recommend starting with B4A-Bridge, which is the simplest connection method.

USB Debug Mode

You will need to first configure your device to support USB debugging (Settings - Developer - USB debugging).

In order to reveal the developer settings you should follow these instructions:
- Choose Settings - About Phone
- Find the Build Number entry and click on it 7 times.
- On many devices you need to set the USB connection type to MTP or PTP.

Not all devices support USB debugging.

B4A-Bridge

B4A-Bridge is made of two components. One component runs on the device and allows the second component which is part of the IDE to connect and communicate with the device.
The connection is done over the local network or with a Bluetooth connection.

Once connected, B4A-Bridge supports all of the IDE features which include: installing applications, viewing the logs, debugging and the visual designer (taking screenshots is not supported).

Android doesn't allow applications to quietly install other applications, therefore when you run your application using B4A-Bridge you will see a dialog asking you to approve the installation.

Getting started with B4A-Bridge
1. First you need to install B4A-Bridge on your device.
B4A-Bridge can be downloaded from Google Play: https://play.google.com/store/apps/details?id=anywheresoftware.b4a.b4abridge

Note that you need to allow installation of applications from "Unknown sources". This is done by choosing Settings from the Home screen - Manage Applications.


2. Run B4A-Bridge on your device. It will display a screen similar to:

arSsfzqjKtq2_v9Moofj4SgiWWet6WOFH-P1Z2NuxbMo4yB6yqsGaoioptbDdbMCZw4=h900



3. Connect the IDE to the device

Go to Tools -> B4A-Bridge -> Connection -> New IP

You will be asked to enter the device IP address. The IP is displayed on the device.

The status bar at the bottom of the screen shows the current status:

SS-2016-09-29_09.31.05.png


SS-2016-09-29_09.31.46.png


That's it.

When B4A-Bridge gets connected it first checks if the designer application needs to be updated. In that case it will first install the designer application.

B4A-Bridge keeps running as a service until you press on the Stop button.
You can always reach it by opening the notifications screen.


As mentioned above, when you run an application you are required to approve the installation. You will usually see the following screens:

SS-2012-03-21_10.50.48.png


Note that the Internet permission is automatically added in debug mode.

SS-2012-03-21_10.52.17.png


In the above dialog you should choose Open to start the application.
If you try to install an existing application signed with a different key, the install will fail (without any meaningful message). You should first uninstall the existing application. Go to the home screen - Settings - Applications - Manage applications - choose the application - Uninstall.

Once you finished developing you should press on the Stop button in order to save battery.

Logs

With B4A-Bridge the logs will only appear in release mode if you add this line to the main module:
B4X:
#BridgeLogger: True
It is better to comment this line before submitting your app to Google Play.


B4A-Bridge source code is available here: http://www.b4x.com/forum/basic4andr...ls/8153-b4a-bridge-source-code.html#post45854

Tip

You can click on the B4A-Bridge status in the IDE to connect or disconnect the bridge.
 

Attachments

  • upload_2016-9-29_9-29-57.png
    upload_2016-9-29_9-29-57.png
    14.3 KB · Views: 6,240
Last edited:

CyclopDroid

Well-Known Member
Licensed User
Longtime User
I've only just added iinto Manifest the code with have found in B4A forum and add the startactivity isgame = true for insert into a game screen on TV (for your app have set = false). ;)
This is the complete code of my Manifest:

B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: http://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="20"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.

' TV Settings
SetApplicationAttribute(android:isGame, "false")   'true to insert into GAME screen
AddManifestText(<uses-feature android:name="android.software.leanback"
                              android:required="false" />       
                <uses-feature android:name="android.hardware.touchscreen"
                              android:required="false" />)
AddActivityText(TvActivity,
                <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
                </intent-filter>)
'END TV SETTING


AddManifestText(<uses-feature android:name="android.hardware.bluetooth" android:required="false"/>)
AddManifestText(<uses-feature android:name="android.hardware.touchscreen" android:required="false"/>)
 

B4AinNY

Member
Licensed User
I have not been able to successfully connect via WiFi - I enter the IP address from B4A Bridge into the Tools / Connect / IP address
but it always reports that it can't find the device.
My Tools Connect does not seem to give me BlueTooth option
I am using B4A in Demo mode ( I don't mind paying $50 - well worth it ) but I'd like to make sure the thing works.
Is B4A Bridge functioning in demo mode ?
 

B4AinNY

Member
Licensed User
OK - Trial or otherwise, I ordered a license just in case.
It still doesn't work.
My Android is connected to WiFi through a router on the same network as the PC.
My Android's IP Address is currently 192.168.1.100
The B4A Bridge on the Android says
Status: Disconnected
Waiting for wireless connections
When I try to connect through B4A Tools / Connect / menu
I get error
Ping failed ( IP = 192.168.1.100 ): Timed Out
The IP Address is most probably incorrect.

Note - I have also bought a USB to Bluetooth for my computer
and have verified a Bluetooth connection between computer and
my Android but B4A doesn't seem to recognize this.

Note - I have also tried direct USB connection from computer to my
Android and I can drag files using FileManager, but apparently B4A
still doesn't recognize this connection either.

- Jeff
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
It looks like a network issue. Maybe your router is configured to block incoming connections.

Anyway, you should use USB debug mode instead.

I have also tried direct USB connection from computer to my
Android and I can drag files using FileManager, but apparently B4A
still doesn't recognize this connection either.
This is not USB debug mode. In order to enable USB debug mode you need to install the USB driver and enable USB debug mode on your device (see the first post).

On most devices you also need to change the USB connection mode from "charge" to PTP.
 

B4AinNY

Member
Licensed User
I never could get the B4A Wifi connection to work,
but I thought I'd post back that USB connection has been working well.
I bought B4A license back in May and have been very happy with it.

- Jeff / B4AinNY
 

victormedranop

Well-Known Member
Licensed User
Longtime User
Hi, I just made a update to version 2.20, but not log display from my apk.

any one have the same problem?

I try to connect with adb an logs are working, but no with the b4x_bridge.

Victor
 
Last edited:

Bob Spielen

Active Member
Licensed User
Hello, I'm trying to enable the logs, but without success. I receive a message :

"LogCat connected to: B4A-Bridge:asus ASUS_X008D
------ beginning of main"

and nothing else .....

I configured my android as developer (7x click on build number), enabled installation of "Unknown sources", debug mode.....
Can any one give me some advice?

I checked if logs were disabled on my device. Turned on and logs worked....
 
Last edited:

B4AinNY

Member
Licensed User
I fi
I never could get the B4A Wifi connection to work,
but I thought I'd post back that USB connection has been working well.
I bought B4A license back in May and have been very happy with it.

- Jeff / B4AinNY

I finally got B4A Bridge WiFi working and thought I should post back my resolution.
Basically I switched from a WiFi router on a LAN to a mobile hotspot device and connected both my tablet and the PC to that. Still no good. Very frustrated I installed today's B4a v 6.80 and B4aBridge v2.30 sure this would fix it. Still no good. Very very frustrated.
Then I had the bright idea finally to try TraceRt to the tablet from my PC and sure enough that failed
even though both were connected to the same WiFi device. This lead me to find a setting in my
Wi-Fi hotspot that was isolating the each device connected to the route. On the Verizon Ellipsis
this is called "Privacy Setting" another name on other devices appears to be "AP Isolation"
This setting needs to be OFF !, That's it. Voila !
I hope this is helpful to others.

- Jeff
 

Petri Savolainen

New Member
Licensed User
Hi,

I am in a situation where i have to do development in a virtual Machine running on Azure.
I cannot run the emulators on azure (no hyper-v stuff). I tried to do the USB-port sharing from local to vm .... did not work.

The bridge would be the perfect solution if it didn't require the dev machine and phone to be in same network.
I tried using ngrok and some putty port forwarding but that didn't work .

any ideas ?

petri.
 

Petri Savolainen

New Member
Licensed User
Thanks, Martin.

I read from somewhere that the port used by b4a-bridge is 6789.
So I installed putty on the vm and forwarded the port 6789 to the address i got from ngrok where I had set up a tcp tunneling to my local pc port 6789. and from my local pc I had putty from 6789 to my phone's ip and 6789 port.

ngrok shows console whenever there's traffic and when I tried to reach the public endpoint of my ngrok-realy it showed that something was going on.
But when I tried to connect b4a-bridge in the Virtual machine it should have talked to the same public endpoint but there was no traffic to be seen... as if putty didn't work or b4a-ide wasn't really talking to 127.0.0.1:6789 ...

So I gave up, bought an extra disk and installed the bloody android sdk there (all 300 G's of it) and hooked it up to my work pc.
Now I have both pc and the phone on same network. And it actually works really nicely.
The wysiwyg-view is really impressive. Now I can concentrate on coding instead of wrestling the infrastructure .

As an extra punishment i have to drag the external hd and some usb-gadgets with me all the time to make this happen but I think the functionality is worth it.

petri.
 

DeSche

New Member
Licensed User
Hi Erel,

I haven't used B4A for some months due to other priorities. Now I'm on vacation, it's raining and I have some Time :)
I've figured out, that B4A-BridgePlus is not working with B4A v6.80 any more. Therefore I've installed B4A-Bridge v2.31. No Problems with the wifi Connection.
But...the developed apk will not be installed on my Samsung S6, even when the the Debug-Window says in the last sentence: "Installing with B4A-Bridge....successfully...."
I also can find a 'temp1.apk' with Correct time and date in /Android/Data/anywheresoftware.b4a.b4abridge/files so I assume, that something on my phone let the apk not install. Any ideas?
As mentioned before, the same project works on the same hardware very well two months ago.
I have Android 7.0 on my phone.

Edit 170628-1524: When I enable USB Debug Mode on my S6 and connect it via USB cable to my V4A Laptop, than the apk get installed. Therefore my assumtion is, that something with the v2.31 B4A-Bridge does not work as designed.
 
Last edited:
Status
Not open for further replies.
Top