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,248
Last edited:

Torby

Member
Licensed User
Longtime User
When I tell the bridge on my android to allow bluetooth connection, it buzzzes 6 times buzzzzz buzzzzz buzzzzz buzzzzzzzzzzzzzzzzzzzzzzzz buzz buzz

It also does this when I stop the bridge from my pc. Perhaps it's just an annoying feature of my Samsung "Charge?"

(I'm loving your product.)
 

BLOKKER

Member
Licensed User
Longtime User
Can you explain please why B4A bridge wants access to phone calls and identity? I can imagine that an apk submitted by bridge is demanding such rights because of design. However B4A bridge is merely a transfer program that launches the installer after successful transferring the apk and do some nifty debugging when the transferred app is running so I can't figger out what the reason is that B4A bridge wants access to something that is not realy needful for its function.
 
Last edited:

qsrtech

Active Member
Licensed User
Longtime User
I'm pretty sure I tried to use bridge on a device with LAN vs wifi and it wouldn't seem to connect. Does it only work with wifi? I'm not sure how it could make any difference.
 

leitor79

Active Member
Licensed User
Longtime User
Hi!

I'm trying to use b4a bridge, I start it on my android, start wireless, go to b4a ide, tools, b4a bridge - connect wireless, set the device IP as shown on b4a bridge, the state on the status bar changes to "connected", but when I run the project... the app is installed on my bluestack app player instance I'm running on my pc (where I have never installed b4a bridge).

Also, I use the "logs" tab, I click "connect", a dialog appears with 2 items, my b4a bridge session and some "emulator-xxxx". I hit the b4a bridge session, I see the log of my device (and updates as my screen goes blank or when I turn it on), but in spite of that, when I run the app it is shown on the bluestacks app player.

Any ideas?


Regards!


PS: I did not try turn the bluestacks app player of since I need it running.
 

leitor79

Active Member
Licensed User
Longtime User
Thanks, Erel.

Since I made the question a few days ago, I've already shut down and turn on my PC, and the problem was gone. But I'll take your advice if it happens again.

Regards!
 

gudino jose luis

Active Member
Licensed User
Longtime User
I had the same problem connecting my device (huawei or samsung tablet)
but with these step fix:

1) the device is off
3) go to the command line (cmd)
2) ping the device, eg 192.168.0.100 -t
3) minimize window command line (cmd)
3) turn on the device
4) turn on dipositive expect and see on the command line the device to answer: Response from 192.168.1.0.100 : byte = 32 .....
5) connect b4a-bridge
6) No close command line (cmd)

Greetings (sorry for my bad English)
 
Last edited:

kiki78

Active Member
Licensed User
Longtime User
Hello Erel,

I start today to continue my development on new tablet.
As I use USB OTG to connect to external device I need B4A Bridge.
I use it without problem on previous tablet since one year.
On new one I can connect with B4A Bridge, install program, but I never see log.
I also try to connect via USB and this work normally with correct log.
I make a little program with OSLibrary that show Device property.

On fresh started tablet this is what I obtain in B4A Log with B4A Bridge and Filter uncheck.
B4X:
LogCat connected to: B4A-Bridge: unknown MPQC1114-138723275017319
--------- beginning of /dev/log/main
error opening trace file: No such file or directory (2)
loaded /system/lib/egl/libEGL_VIVANTE.so
loaded /system/lib/egl/libGLESv1_CM_VIVANTE.so
loaded /system/lib/egl/libGLESv2_VIVANTE.so
Enabling debug mode 0
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (service1) Create **
** Service (service1) Start **
GC_CONCURRENT freed 237K, 8% free 6274K/6791K, paused 2ms+2ms, total 27ms
Connected to B4A-Bridge (Wifi)
** Activity (main) Pause, UserClosed = false **
Installing file.
PackageAdded: package:b4a.example

This is what I obtain with USB Cable (with Filter check)
B4X:
LogCat connected to: 0123456789ABCDEF
--------- beginning of /dev/log/main
--------- beginning of /dev/log/system
** Activity (main) Create, isFirst = true **
Device = gs702a
** Activity (main) Resume **

B4A 3.50, Bridge 2.09

Have you an idea ?
 

Attachments

  • Log with USB Cable Without Filter.zip
    19.1 KB · Views: 470

kiki78

Active Member
Licensed User
Longtime User
I just test it and that's work on Debug mode. Thank you Erel for quick response :)

For information, my previous tablet (Samsung Galaxy Note 10.1) is with version 4.1.2 and show log in Release mode also.
The new one is 4.1.1.

Another difference is when Filter is uncheck, I only see very small log on new one as opposed than Note or also with USB cable.
Is it normal ?
 

Sannie72

Member
Licensed User
Longtime User
Hello Erel,

I found an odd behaviour with B4A-Bridge v2.09 since I installed the latest B4A version 3.50. I am a registered user. Before 3.50 everything worked fine.
Now the following happens:
I can connect without a problem over WiFi. When I hit F5 (or Alt-1) a screen appears on the device showing the permissions of the new app. At the bottom of this screen there are two buttons: 'Cancel' and 'Install'. The Cancel button works as expected, but the Install button does not respond. Also changing the orientation of the device does not help. Logcat shows the following:
B4X:
LogCat connected to: B4A-Bridge: samsung GT-I9300-352993059312512
--------- beginning of /dev/log/main
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (service1) Create **
** Service (service1) Start **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
Connected to B4A-Bridge (Wifi)
Streams_terminated
Connected to B4A-Bridge (Wifi)
Installing file.
** Activity (main) Pause, UserClosed = false **
Running B4A version 3.50 on Windows 7 Enterprise SP1, mobile device Samsung GT-I9300.
What can I do to make this work again?
 

Sannie72

Member
Licensed User
Longtime User
It is most probably not related to a change in v3.50. Does it happen with any app you try to install?
I tried also with a completely new project; I created a hello world with one activity and a label, but that also does not work. USB works fine, but B4A-Bridge in Wireless mode does not.
I get to the point where I have to click 'Install', but the button does not respond.
 
Status
Not open for further replies.
Top