Android Question Getting Bluetooth Device ID

Graeme Tacon

Member
Licensed User
Longtime User
Hi

Fairly new to using B4A, so excuse me if this is a silly problem.

I've created a service to capture "android.bluetooth.device.action.ACL_CONNECTED" and then want to pick out the Device ID from the intent.

I've tried the code below, but that comes back as null.

ToastMessageShow(StartingIntent.GetExtra("android.bluetooth.device.extra.DEVICE"),True)

Using the following, does show that the detail is in the message:
ToastMessageShow(StartingIntent.ExtrasToString,True)

Bundle[{android.bluetooth.device.extra.DEVICE�:A4E:A7:9CF, android.bluetooth.device.extra.LINKTYPE= android.bluetooth.device.extra.DISCONNECTION_REASON=]

What am I doing wrong ?!

Thanks
 

Graeme Tacon

Member
Licensed User
Longtime User
Out from log as requested:

Bundle[{android.bluetooth.device.extra.DEVICE=E45:3D:E2:42:46, android.bluetooth.device.extra.LINKTYPE=0, android.bluetooth.device.extra.DISCONNECTION_REASON=0}]
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Try this:
B4X:
Sub Service_Start(startingIntent As Intent)
   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"))
     Log(bd.RunMethod("getName", Null))
     Log(bd.RunMethod("getAddress", Null))
   End If
End Sub
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
@Erel: Please where could we find information about the method you have used with JavaObject to achieve this ? It is totally unknown for me and I guess I could do more things with this knowledge.
Many thanks
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…