Android Question bluetooth, phone and distance

popeyes44

New Member
Hi everycoders ;-),

I try to realize an application for android (iOS in future surely) but have little difficulties.

The idea is to discover phone in my family (using BLEManager library because using GPS is too bad on my test [few meters errors...]) which all have the program installed on. For do that I know I need to make them always discoverable :

B4X:
Intent1.Initialize("BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE", "")
Intent1.PutExtra("BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION",600)
StartActivity(Intent1)

and use that for found device

B4X:
Sub BLuE1_DeviceFound (Name As String, Id As String, AdvertisingData As Map, RSSI As Double)
    Log("Name= " & Name & ", ID= " & Id & ", RSSI= " & RSSI & ", AD= " & AdvertisingData)   
End Sub

All is OK at this point but I need to limit (or calcul) distance between my phone and bluetooth search, so do you find it's possible and, if yes, how could I do that ? Or maybe I could estimate distance with bluetooth data but I don't know how ?

Thanks all for helping
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You are confusing classic Bluetooth and BLE.

You can use BLEPeripheral to advertise some information and detect it with BLEManager. You can also calculate the distance however it will be very inaccurate.

If the devices are connected to the same network then you can use UDP broadcasting to detect other devices. This will work better.
 
Upvote 0
Top