Serial library v1.20 - BluetoothAdmin and insecure connections

Erel

B4X founder
Staff member
Licensed User
Longtime User
This update adds a new type of object - BluetoothAdmin. This object supports administration of the Bluetooth adapter including discovery of new devices.

Two new methods were added to Serial object: ConnectInsecure and ListenInsecure. These methods which are based on native methods that are not part of the formal API, allow you to make unencrypted connections.

The documentation is available here: Basic4android - Serial
Installation instructions:
- Download the attached file.
- Copy both files to the internal libraries folder: C:\Program Files\Anywhere Software\Basic4android\Libraries
 

Attachments

  • Serial.zip
    11.6 KB · Views: 1,990

rbsoft

Active Member
Licensed User
Longtime User
Thanks a lot for the BTAdmin functionality.

Question:
Is there any event raised in case a device gets out of range so that the connection gets interrupted?

(If not it is not too much of a problem - I could react if I get no answer from the device.)

Rolf
 

rbsoft

Active Member
Licensed User
Longtime User
Thanks, Erel, I'm gonna try it out.

Rolf
 

glouie

Member
Licensed User
Longtime User
Thanks for the updated library, before using BTadmin I had to ask the user to turn on BT and bring up the setting screen using an intent and now I can do it automatically.

One question I have is if there is a way to detect whether or not a BT device is connected to the phone?

Right now I can check to see if it is paired but do not know if it is connected. This BT device is using HID and not SPP so I am not sure if this is supported by the serial library because I cannot connect to it when I call the

Any advice would be greatly appreciated, thank you for the great new features.
 

ondesic

Active Member
Licensed User
Longtime User
I am trying to use this bluetoothadmin to start the Discoverable state on my device. However, after initiating StartDiscovery, I will quickly switch to the settings, but Discoverable mode is not on.

I also put a toast message in the DiscoveryStarted and DiscoveryFinished events. It seems as though 5 seconds after the DiscoveryStarted event fires, the Finished event is fired.

Basically, I can't seem to make my device discoverable with code alone. Am I missing something?
 

manios

Active Member
Licensed User
Longtime User
You might misunderstand what the Command will do, StartDiscovery means the device starts looking for other devices. It will not make your device discoverable.
 

ondesic

Active Member
Licensed User
Longtime User
You are right. I thought this made the device discoverable. After more searching I came on one thread that sent me in the right direction. The code to turn on discoverable mode for 60 seconds is:

B4X:
Dim Intent1 As Intent
 
Intent1.Initialize("android.bluetooth.adapter.action.REQUEST_DISCOVERABLE", "")
Intent1.PutExtra("android.bluetooth.adapter.extra.DISCOVERABLE_DURATION",60)
StartActivity(Intent1)
 
Last edited:

shmulik taiber

Member
Licensed User
Longtime User
This update adds a new type of object - BluetoothAdmin. This object supports administration of the Bluetooth adapter including discovery of new devices.

Two new methods were added to Serial object: ConnectInsecure and ListenInsecure. These methods which are based on native methods that are not part of the formal API, allow you to make unencrypted connections.

The documentation is available here: Basic4android - Serial
Installation instructions:
- Download the attached file.
- Copy both files to the internal libraries folder: C:\Program Files\Anywhere Software\Basic4android\Libraries
sorry for the rookie question - I've downloaded and unzipped the files attached above, but they are not B4A . how can i open and run them ?
 

shmulik taiber

Member
Licensed User
Longtime User
too late for that Erel.... I've already downloaded and replaced the files.... any solution to restore the updated ones?
Aside from that, I have no idea how to access or use the libraries in B4A . any guidance shall be appreciated and time saving....
 

positrom2

Active Member
Licensed User
Longtime User
Erel wrote:
A newer version of Serial library is already included in the IDE. You should not download this library.
I don't understand. I am also using the downloaded Serial lib. But when I unckeck the lib - as I understand the meaning of
included in the IDE
then
B4X:
Dim ... as Serial
gets red colored.
 

MaFu

Well-Known Member
Licensed User
Longtime User

MaFu

Well-Known Member
Licensed User
Longtime User
Erel wrote:

I don't understand. I am also using the downloaded Serial lib. But when I unckeck the lib - as I understand the meaning of then
B4X:
Dim ... as Serial
gets red colored.

Don't uncheck the lib.
Erel means, the serial lib files shipped with B4A are the newer one. The serial lib from this thread is outdated.
If you have the downloaded files in your "additional librarys" folder, delete it.
If you have replaced the files in the "libraries" folder, reinstall B4A (takes one minute).
 

irda

Member
Licensed User
Longtime User
Hello, I'm use this library with astreams but i have a problem. I send some bytes but at debug windows I recive another values, for example, I send via PC bluetooth this bytes:

255 255 128 127 100 50 0

But "Sub AStream_NewData (Buffer() As Byte)" recibe

-1 -1 -128 127 100 50 0

Only values under 127, Can anyone help me?

Thanks
 

Frank LaVerne

New Member
Licensed User
Longtime User
Hi guys,

I am having a little problem with the serial library in terms of using the function Listen2. In the doc it says:

Listen2 (Name AsString, UUID AsString)

I especially needed the UUID part, because I need some specific static UUID to be found by a device looking for bluetooth services.

Problem is: No matter what I provide, the name permanently is "B4A", the UUID permanently is "00001101-0000-1000-8000-00805F9B34FB". It nearly looks like that "Listen2" is doing not a lot more than "Listen", at least for me under my circumstances. Though all I do is defining a "Serial" as a global and then initialize it with "Listen2", like so:

Serial1.Listen2("MyCustomServiceName", "00000000-0010-1337-8001-0DFA4A1E4438")

Editing the class binary file in the Serial.jar did the trick as a dirty workaround - so if I cange the values there (hardcoded), I am able to spot them when looking for bluetooth services via sdptool. But I don't feel comfortable using this as a permanent workaround.

Could this be a little bug in the serial library, or am I missing out something vital?

Last but not least: Erel - keep up the good work, you are doing an amazing job. I've been a developer for more than 20 years now, and I have tried a lot to ease the pain of developing for Android, but B4A is the slimmest and finest solution there is.

Cheers,

Frank
 

Frank LaVerne

New Member
Licensed User
Longtime User
So true - sorry Erel, my bad.

Looks like I had a bit of a misunderstanding about the conceptions of a Service module, in which I couldn't make the function "Listen2" work as expected. When I tested it in my main activity, I got it working. When I then remodeled the Service module, it finally worked as well.

Thanks for checking.
 
Top