I had code that caught some undocumented intents on Android 2.2+, but this code doesn't seem to work on ICS. What I'd like to do is detect when a headset connects/disconnects and perform certain actions. Currently I have the following Scala code:

  private def initSCOV11() {
    bluetoothAdapter = BluetoothAdapter.getDefaultAdapter

    val listener = new BluetoothProfile.ServiceListener {

      def onServiceConnected(profile:Int, proxy:BluetoothProfile) {
        Log.d("spielcheck", "Profile: "+profile+", Proxy: "+proxy)
        Log.d("spielcheck", proxy.getConnectedDevices.toString)
      }

      def onServiceDisconnected(profile:Int) {
        Log.d("spielcheck", "Profile: "+profile)
        if(profile == BluetoothProfile.HEADSET)
          bluetoothHeadsetDisconnected()
      }

    }

Log.d("spielcheck", "Value: "+bluetoothAdapter.getProfileProxy(service, listener, BluetoothProfile.HEADSET))
  }

getProfileProxy returns true, and the onServiceConnected gets called. If there are no headsets connected, the list is empty, but with my SCO earpiece connected, I get its MAC address in the list. This seems odd to me, since if no headsets are connected, I'd not expect this method to get called at all.

My assumption was that this code would trigger whenever a headset is connected or disconnected from the device, but I've activated/deactivated both SCO and A2DP headsets and the callbacks aren't triggered. I must be misunderstanding what these callbacks do. Instead of being called when individual devices connect/disconnect, they must be called when the profiles are available to be queried or something.

How do I set up code to run when a headset connects/disconnects?

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to