Message info From:Alger Lin Subject:[android-developers] Re: Detecting headset connection/disconnection on Android 3.0+ Date:Thu, 29 Mar 2012 00:09:41 -0700 (PDT)

I release a tool to dumping all classes (includes disclosed and undocumented) at device,  maybe this tool can help you to check if undocumented API was available at target Android version. 

You can get it by URL below.

Nolan Darilek 2012~320PGUTC+8W13918gDG
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)


     Log.d("spielcheck", "Value:
"+bluetoothAdapter.getProfileProxy(service, listener,

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
To unsubscribe from this group, send email to
For more options, visit this group at