fm/fmapp2/src/com/caf/fmradio/FMTransmitterService.java
public void registerHeadsetListener() {
       if (mHeadsetReceiver == null) {
           mHeadsetReceiver = new BroadcastReceiver() {
               @Override
               public void onReceive(Context context, Intent intent) {
                   String action = intent.getAction();
                   if (action.equals(Intent.ACTION_HEADSET_PLUG)) {
                      Log.d(LOGTAG, "ACTION_HEADSET_PLUG Intent received");
                      // Listen for ACTION_HEADSET_PLUG broadcasts.
                      Log.d(LOGTAG, "mTransmitter: ACTION_HEADSET_PLUG");
                      Log.d(LOGTAG, "==> intent: " + intent);
                      Log.d(LOGTAG, "    state: " + intent.getIntExtra("state", 0));
                      Log.d(LOGTAG, "    name: " + intent.getStringExtra("name"));
                      mHeadsetPlugged = (intent.getIntExtra("state", 0) == 1);
                      mHandler.post(mChangeFMTxState);

                   } else if (mA2dpDeviceState.isA2dpStateChange(action)) {
                       if (mA2dpDeviceState.isConnected(intent)){
                           Log.d(LOGTAG, " A2DP connected");
                           mHeadsetPlugged = true;
                           if( mFMOn == true)
                           {
                               mHandler.post(mChangeFMTxState);
                           }
                       } else if( !mA2dpDeviceState.isConnected(intent)) {
                           Log.d(LOGTAG, "A2DP disconnected");
                           mHeadsetPlugged = false;
                           if( mFMOn == false) // when FM Tx App open, DISC BT
                           {
                               Log.d(LOGTAG, "posting for a2dp state change");
                               mHandler.post(mChangeFMTxState);
                           }
                       }
                   } else if (action.equals("HDMI_CONNECTED")) {
                       if( mFMOn == true) {
                           Log.d(LOGTAG, "posting for hdmi state change");
                           mHandler.post(mChangeFMTxState);
                       }
                   }
               }
           };
           IntentFilter iFilter = new IntentFilter();
           iFilter.addAction(Intent.ACTION_HEADSET_PLUG);
           iFilter.addAction(mA2dpDeviceState.getActionSinkStateChangedString());
           iFilter.addAction(mA2dpDeviceState.getActionPlayStateChangedString());
           iFilter.addAction("HDMI_CONNECTED");
           iFilter.addCategory(Intent.CATEGORY_DEFAULT);
           registerReceiver(mHeadsetReceiver, iFilter);
       }
   }
/**
    * Registers an intent to listen for ACTION_HEADSET_PLUG
    * notifications. This intent is called to know if the headset
    * was plugged in/out
    */
Registers an intent to listen for ACTION_HEADSET_PLUG
notifications. This intent is called to know if the headset
was plugged in/out
Registers an intent to listen for ACTION_HEADSET_PLUG notifications . This intent is called to know if the headset was plugged in / out
public void registerHeadsetListener() {
       if (mHeadsetReceiver == null) {
           mHeadsetReceiver = new BroadcastReceiver() {
               @Override
               public void onReceive(Context context, Intent intent) {
                   String action = intent.getAction();
                   if (action.equals(Intent.ACTION_HEADSET_PLUG)) {
                      Log.d(LOGTAG, "ACTION_HEADSET_PLUG Intent received");
                      Log.d(LOGTAG, "mTransmitter: ACTION_HEADSET_PLUG");
                      Log.d(LOGTAG, "==> intent: " + intent);
                      Log.d(LOGTAG, "    state: " + intent.getIntExtra("state", 0));
                      Log.d(LOGTAG, "    name: " + intent.getStringExtra("name"));
                      mHeadsetPlugged = (intent.getIntExtra("state", 0) == 1);
                      mHandler.post(mChangeFMTxState);
                   } else if (mA2dpDeviceState.isA2dpStateChange(action)) {
                       if (mA2dpDeviceState.isConnected(intent)){
                           Log.d(LOGTAG, " A2DP connected");
                           mHeadsetPlugged = true;
                           if( mFMOn == true)
                           {
                               mHandler.post(mChangeFMTxState);
                           }
                       } else if( !mA2dpDeviceState.isConnected(intent)) {
                           Log.d(LOGTAG, "A2DP disconnected");
                           mHeadsetPlugged = false;
                           if( mFMOn == false) 
                           {
                               Log.d(LOGTAG, "posting for a2dp state change");
                               mHandler.post(mChangeFMTxState);
                           }
                       }
                   } else if (action.equals("HDMI_CONNECTED")) {
                       if( mFMOn == true) {
                           Log.d(LOGTAG, "posting for hdmi state change");
                           mHandler.post(mChangeFMTxState);
                       }
                   }
               }
           };
           IntentFilter iFilter = new IntentFilter();
           iFilter.addAction(Intent.ACTION_HEADSET_PLUG);
           iFilter.addAction(mA2dpDeviceState.getActionSinkStateChangedString());
           iFilter.addAction(mA2dpDeviceState.getActionPlayStateChangedString());
           iFilter.addAction("HDMI_CONNECTED");
           iFilter.addCategory(Intent.CATEGORY_DEFAULT);
           registerReceiver(mHeadsetReceiver, iFilter);
       }
   }
public void registerHeadsetListener ( ) { if ( mHeadsetReceiver == null ) { mHeadsetReceiver = new BroadcastReceiver ( ) { @ Override public void onReceive ( Context context , Intent intent ) { String action = intent . getAction ( ) ; if ( action . equals ( Intent . ACTION_HEADSET_PLUG ) ) { Log . d ( LOGTAG , "ACTION_HEADSET_PLUG Intent received" ) ; Log . d ( LOGTAG , "mTransmitter: ACTION_HEADSET_PLUG" ) ; Log . d ( LOGTAG , "==> intent: " + intent ) ; Log . d ( LOGTAG , "    state: " + intent . getIntExtra ( "state" , 0 ) ) ; Log . d ( LOGTAG , "    name: " + intent . getStringExtra ( "name" ) ) ; mHeadsetPlugged = ( intent . getIntExtra ( "state" , 0 ) == 1 ) ; mHandler . post ( mChangeFMTxState ) ; } else if ( mA2dpDeviceState . isA2dpStateChange ( action ) ) { if ( mA2dpDeviceState . isConnected ( intent ) ) { Log . d ( LOGTAG , " A2DP connected" ) ; mHeadsetPlugged = true ; if ( mFMOn == true ) { mHandler . post ( mChangeFMTxState ) ; } } else if ( ! mA2dpDeviceState . isConnected ( intent ) ) { Log . d ( LOGTAG , "A2DP disconnected" ) ; mHeadsetPlugged = false ; if ( mFMOn == false ) { Log . d ( LOGTAG , "posting for a2dp state change" ) ; mHandler . post ( mChangeFMTxState ) ; } } } else if ( action . equals ( "HDMI_CONNECTED" ) ) { if ( mFMOn == true ) { Log . d ( LOGTAG , "posting for hdmi state change" ) ; mHandler . post ( mChangeFMTxState ) ; } } } } ; IntentFilter iFilter = new IntentFilter ( ) ; iFilter . addAction ( Intent . ACTION_HEADSET_PLUG ) ; iFilter . addAction ( mA2dpDeviceState . getActionSinkStateChangedString ( ) ) ; iFilter . addAction ( mA2dpDeviceState . getActionPlayStateChangedString ( ) ) ; iFilter . addAction ( "HDMI_CONNECTED" ) ; iFilter . addCategory ( Intent . CATEGORY_DEFAULT ) ; registerReceiver ( mHeadsetReceiver , iFilter ) ; } }
Registers an intent to listen for ACTION_HEADSET_PLUG
 notifications.
Registers an intent to listen for ACTION_HEADSET_PLUG notifications .
// Listen for ACTION_HEADSET_PLUG broadcasts. // when FM Tx App open, DISC BT