Android Question Receiver service starting intent bluetooth extras problem

Hi all,

in my project there's a service module that listen for the ACTION_ACL_DISCONNECTED event.
When it occurs, I want to analyze the intent's extras available in the Service_Start Sub.
In the Android developer page they said that the Broadcast Action "Always contains the extra fields EXTRA_DEVICE and EXTRA_TRANSPORT".
Unfortunately in the starting intent of my service I'm not able to extract these information.
If I call
B4X:
Intent.ExtrasToString
it returns an android Bundle with some data, included the EXTRA_DEVICE extra (in fact if I call
B4X:
Intent.HasExtra(EXTRA_DEVICE)
it returns true).
But when I call
B4X:
Intent.GetExtra(EXTRA_DEVICE)
it always returns Null.
Am I missing something here?

Attached you can find an example project.
 

Attachments

  • Prova1.zip
    11.5 KB · Views: 215
Solution
Should be:
B4X:
Dim BluetoothDevice As JavaObject = Intent.As(JavaObject).RunMethod("getParcelableExtra", Array("android.bluetooth.device.extra.DEVICE"))
Hi Erel,
the output depends on the device the app's running on.
On Samsung Galaxy Tab A7 Lite (API 30) the output is:
B4X:
ExtrasToString: Bundle[{com.samsung.bluetooth.device.extra.LINKTYPE=1, android.bluetooth.device.extra.DEVICE=98:D3:31:F5:CA:72, com.samsung.bluetooth.device.extra.DISCONNECTION_REASON=8}]

On Wiko Lenny 3 (API 23) the output is:
B4X:
ExtrasToString: Bundle[{android.bluetooth.device.extra.DEVICE=98:D3:31:F5:CA:72}]

In any case there's always at least the EXTRA_DEVICE as the intent's extra.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…