B Black&WhiteStar Member Apr 14, 2022 #1 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 Prova1.zip 11.5 KB · Views: 510
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.
Solution Erel Apr 14, 2022 Should be: Code: Dim BluetoothDevice As JavaObject = Intent.As(JavaObject).RunMethod("getParcelableExtra", Array("android.bluetooth.device.extra.DEVICE"))
Should be: Code: Dim BluetoothDevice As JavaObject = Intent.As(JavaObject).RunMethod("getParcelableExtra", Array("android.bluetooth.device.extra.DEVICE"))
Erel B4X founder Staff member Licensed User Longtime User Apr 14, 2022 #2 What is the output of Log(Intent.ExtrasToString) ? Upvote 0
B Black&WhiteStar Member Apr 14, 2022 #3 Hi Erel, the output depends on the device the app's running on. On Samsung Galaxy Tab A7 Lite (API 30) the output is: Code: 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: Code: 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
Hi Erel, the output depends on the device the app's running on. On Samsung Galaxy Tab A7 Lite (API 30) the output is: Code: 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: Code: 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.
Erel B4X founder Staff member Licensed User Longtime User Apr 14, 2022 #4 Should be: Code: Dim BluetoothDevice As JavaObject = Intent.As(JavaObject).RunMethod("getParcelableExtra", Array("android.bluetooth.device.extra.DEVICE")) Upvote 0 Solution
Should be: Code: Dim BluetoothDevice As JavaObject = Intent.As(JavaObject).RunMethod("getParcelableExtra", Array("android.bluetooth.device.extra.DEVICE"))