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
it works fine
but suppose to have a bleutooth headset already connected before to start application
when i start the application and the listener service (s2), the first log are:
(Intent) Intent { cmp=com.breltolab.drivi/.servicebluetooth }
no extras
subsequent log are then corrected based on the state of connection of the headset bluetooth
any idea?
1. You can distinguish between ACTION_ACL_CONNECTED to ACTION_ACL_DISCONNECTED by checking Intent.Action.
2. See the intent filters tutorial. Your application will intercept all intents. It doesn't matter whether it was running or not.
ok, but my problem is that the bluetooth is already connected and when i run the service the StartingIntent.ExtrasToString variable the first time returns "noextras"
Also StartingIntent.Action is empty.
Only disconnecting and reconnecting the bluetooth during the service run, the service intercept the intent with value ACTION_ACL_CONNECTED and ACTION_ACL_DISCONNECTED (in property StartingIntent.ExtrasToString)
yes the permission is in manifest file and infact the listener service works perfectly if i connect or disconnect the bluetooth device
My goal is to check if is connected or not when i start the application
Also if the bluetooth device is connected when run the application (that run the listener service) StartingIntent.ExtrasToString is empty
I repeat that my goal is to check if the bluetooth headset is connected when i start the application not only when it is disconnected or connected during application execution.
If the bluetooth device is already connected when i start application (and listener service), the log are empty!!!!!!!!
First, the first time i run the app, i do not know if the bluetooth is connected or not (I know just after the start, when the status BT changed)
Also:
1. first run, save state BT (connected or not. suppose yes)
2. close application
3. disconnect BT
4. run application
5. load state BT (connected) when in really is not
I could use a static function that works on all devices
In fact, repeat that if the device is already connected before starting the application, the StartingIntent.ExtrasToString (when you start the application and then the listener service) is empty because there was no event (about disconnect/connect BT)
After the service listener it works fine when you disconnect or connect the bluetooth device but the first time i do not know the status
I'm not a expert, but this worked for me.
you need to search for serial samples
Hope this helps:
Try
Serial1.Connect3(Your bluetooth,1)
Catch
Msgbox("Error connecting to " & your bluetooth,"")
End Try
Sub Serial1_Connected (Success As Boolean)
If Success Then
Log("Bt_Connected")
Else
Log("Bt_Not_Connected")
End If
End Sub
...
As the ACTION_SCO_AUDIO_STATE_UPDATED intent is sticky, the application can check the SCO audio state before calling startBluetoothSco() by reading the intent returned by the receiver registration. If the state is already CONNECTED, no state change will be received via the intent after calling startBluetoothSco(). It is however useful to call startBluetoothSco() so that the connection stays active in case the current initiator stops the connection.
Unless the connection is already active as described above, the state will always transition from DISCONNECTED to CONNECTING and then either to CONNECTED if the connection succeeds or back to DISCONNECTED if the connection fails (e.g no headset is connected).