Android Question Getting Connected Bluetooth Device Details?

Mark Hollingworth

Member
Licensed User
Longtime User
I am trying to find a way for my app to be able to query a bluetooth device name and address when it starts up, if the device is already connected, using the stock bluetooth connection (turn on bluetooth through android settings and select the device to connect too). I know I can do this with intents when a device connects, using a service and listening for the CONNECTED intent but if I stop the service then start it again the CONNECTED intent is not fired if the bluetooth device is already connected.

So my question is can you get the details of a bluetooth device that is already connected when an app starts up?
 

Mark Hollingworth

Member
Licensed User
Longtime User
Thanks Erel,

So basically the answer is no you cant query a connected Bluetooth device without using the CONNECTED Intent.

I know about Static intents and do already have them setup as a service. Maybe I didn't explain myself properly I am thinking about the situation (might only happen once) when an app is first installed, the services have not been run before but the Bluetooth is already connected to a device, the service spins up but it wont get called as the intent has already been fired before the app started so there is no record of it, using BluetoothAdmin I can see that Bluetooth is enabled but cannot see if there is anything actually connected.

Is the only solution to ask the user to reconnect the Bluetooth so that the service can then pick up the CONNECTED Intent and pull out the connected device details or show a list of all the Paired devices and asking them to select which is connected?

B4X:
If StartingIntent.Action = "android.bluetooth.device.action.ACL_CONNECTED" Then
       Dim io As JavaObject = StartingIntent
       Dim bd As JavaObject = io.RunMethod("getParcelableExtra", Array As Object("android.bluetooth.device.extra.DEVICE"))
       ConnectedDeviceName = (bd.RunMethod("getName", Null))
       ConnectedDeviceAddress = (bd.RunMethod("getAddress", Null))
End If
 
Upvote 0
Top