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

Brad

Active Member
Licensed User
Longtime User
I feel like a kid in a candy store asking for more candy but...any chance of having the bridge keeping the device awake once connected?
 

agraham

Expert
Licensed User
Longtime User
I assume, from your other posts, that it is the desktop code you want.

EDIT:- Sorry, I didn't look closely enough and assumed you were user metrick who also requested source code, I now see you are not!
 

Attachments

  • B4ABridgePlus1.1.sbp.zip
    4.2 KB · Views: 650
Last edited:

devjet

Member
Licensed User
Longtime User
Is there a way to transfer any other date using this tool like pdf files etc, or can one only install the application. The tool works better than any connection I have seen so far and I would love to be able to move other data as well

Regards
Hans
 

junglejet

Active Member
Licensed User
Longtime User
While I can load and run applications through the B4a bridge, it appears I am unable to use the B4a designer on my smartphone.

When I connect from the Designer dialog on my desktop the designer on the device immediately shows up, but no entities on it, just a black screen.

On the desktop the message "Connecting to device. This may take several minutes" remains.

I must admit that I use the bridge between two separate networks. I do some NAT translation to get through the firewalls. I have setup everything for port 6789. Maybe that is not enough?

Thanks
Andy
 

junglejet

Active Member
Licensed User
Longtime User
I found the designer listens on port 5000. When enabled this port it works.

Can I change these ports (5000, 6789) somewhere? I have another application using it already.

Thanks.
Andy
 

junglejet

Active Member
Licensed User
Longtime User
I have separate networks for LAN and WLAN. This is why I need to use a NAT translation.
I have another specific application behind the NAT router that must expose port 5000. Not changeable.
It is not related to Android.
I will find a work around :)

Thanks for help
Andy
 

junglejet

Active Member
Licensed User
Longtime User
I have a 160x240 device that I can better position the entities on its screen.

Thanks
Andy
 

hyuk7

New Member
Licensed User
Longtime User
B4A-Bridge, can design, but can't run directly...

hi,
I recently purchased the Samsung Galaxy Tab,
and B4A-bridge is well connected to the device and IDE.
I can design the layout on the device via the bridge.
however, it's yet impossible to run directly from the PC.
When I tried to run from the IDE, then the connection been lost & the Tab freezing few seconds and an error message popped up to ask to kill the B4A-bridge.
So I use the USB connection to copy the result.apk, then install it on the device... and it runs OK.
What did I missed or what should I do to compile & run through the B4A-bridge? :sign0085:
Thanks.
 

konradwalsh

Active Member
Licensed User
Longtime User
Solved - FOr Me At Least

I wasted three hours on this issue

I found the issue was on my router.. AP Isolation was on.. So two wireless devices wouldnt talk to each other..

hope it helps someone else
 

hyuk7

New Member
Licensed User
Longtime User
Please check the unfiltered log. It should contain a stack trace with the error that caused B4A-Bridge to fail. Right click on the log, copy the error and post it here.

this is the filtered log just before the B4A-bridge is freezing.

+++++++++++++++++++ from here ++++++++++++++++++++
LogCat connected to: B4A-Bridge: samsung GT-P1000T-00000000000000
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (service1) Create **
** Service (service1) Start **
** Service (service1) Start **
Connected to B4A-Bridge
Installing file. +++++++++ it can be run from the IDE if I don't use the B4A-Designer on the device.
** Activity (main) Pause, UserClosed = false **
PackageAdded: package:anywheresoftware.b4a.samples.guessmynumber
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Activity (main) Resume **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (service1) Create **
** Service (service1) Start **
** Service (service1) Start **
Connected to B4A-Bridge
+++++++++++++++++ to here ++++++++++++++++++

Once the bridge is not responding, no logs available. So i couldn't trace the problem.:BangHead:

instead, I found that the Bridge is freezing when the B4A-Designer on the device is used.
So everytime when I design a layout,
1. save the design & close the Designer
2. kill the B4A-Bridge in the Task Manager
3. re-run the Bridge & connect it again
4. then the application can be run from the IDE

There is no problem to run the application from the IDE if I don't design layouts through the B4A-Bridge. :sign0060:

Anyway I hope it can be solved on my machines in the near future.
Thanks.
 
Last edited:
Status
Not open for further replies.
Top