Check bluetooth headset is connected

brelto85

Active Member
Licensed User
Longtime User
After my post, i need to determinate if the bluetooth headset is connected

looking for the internet i found the isBluetoothScoOn() method:

B4X:
Sub IsBluetoothHeadsetOn As Boolean
    Dim r As Reflector
    r.Target = r.GetContext
    r.Target = r.RunMethod2("getSystemService", "audio", "java.lang.String")
    Return r.RunMethod("isBluetoothScoOn")
End Sub

but this method not works on my phone and in this link explains that this feature works only on rooted devices

There are other solutions?
someone has tested?

thanks
alberto
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Note that this event is only available in Android 4+. You will not be able to get the immediate result (because of the "sticky" intent) without writing a small library. You can however add an intent filter and track the events.

Again, it doesn't matter whether your application is running or not. The process will be started when the event fires.
 
Upvote 0

brelto85

Active Member
Licensed User
Longtime User
Erel, now i understand what you meant when you wrote that the recorded intent is executed even if the application is not active

Anyway, the first time you install the application and the first time runs, nothing will be recorded until connect or disconnect the bluetooth headset.

I ask at this point:

1. is there a way to force the disconnect and reconnect the Bluetooth headset?
2. there is a type "ACTION_ACL_CONNECTED" but only intercepts the type bluetooth headset and not all bluetooth devices?
3. when you run the intent (especially when the application is not active), how can i save the state of bluetooth headset? through the StateManager?

thanks
 
Upvote 0

brelto85

Active Member
Licensed User
Longtime User
1. Ok
2. For example? i need an Intent that works for all android versions
3. Then StateManager works also if the application is not running?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please do not "bump" threads.

As far as I know the only intents available on all Android devices is the ACL connected / disconnected intents.

Then StateManager works also if the application is not running?
As I wrote about 5 times in this thread the process will start when the intent is received. While the activity will not be displayed the application will actually run.
 
Upvote 0
Top