title: How to connect an app to a Bluetooth headset
body: <p>I am trying to connect my application to a bluetooth headset but I get errors for <code>mProfileListener</code>. I am not sure where and how to declare <code>mProfileListener</code>.
   Here is my code:</p>
  
  <pre><code>// Get the default adapter
     BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
  
  
  // Establish connection to the proxy.
     mBluetoothAdapter.getProfileProxy(this, mProfileListener, BluetoothProfile.HEADSET);
  
     private BluetoothProfile.ServiceListener mProfileListener = new BluetoothProfile.ServiceListener() {
         public void onServiceConnected(int profile, BluetoothProfile proxy) {
             if (profile == BluetoothProfile.HEADSET) {
                 mBluetoothHeadset = (BluetoothHeadset) proxy;
                 Log.d("TAGP","BLuetooth Headset: "+mBluetoothHeadset);
                 Log.d("TAGP ","Proxy: "+proxy);
             }
         }
         public void onServiceDisconnected(int profile) {
             if (profile == BluetoothProfile.HEADSET) {
                 mBluetoothHeadset = null;
             }
         }
     };
  
     // ... call functions on mBluetoothHeadset
  
     // Close proxy connection after use.
     mBluetoothAdapter.closeProfileProxy(mBluetoothHeadset);
  
  }
  </code></pre>