Followers

Monday, October 22, 2012

Hide and Show Button on HeadPhone Attached and Detached

Broadcast receiver,displays and hide button, when we attach or detach(remove) the headphone.

Action Used is : ACTION_HEADSET_PLUG
Check state : if state is 0 means headset/headphone was removed else it is attached.



private final BroadcastReceiver headsetReceiver = new BroadcastReceiver() {

@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();

if ((action.compareTo(Intent.ACTION_HEADSET_PLUG)) == 0) // if the
// action match a headset one
{

int headSetState = intent.getIntExtra("state", 0); // get the
// headset state property
// Log.i("XML", "Headset Microphone : " + hasMicrophone);
if (btn != null) {
if (headSetState == 0) // headset was unplugged & has no microphone
{
btn.setVisibility(View.INVISIBLE);
} else {
btn.setVisibility(View.VISIBLE);
}
}
}

}

};

2 comments:

  1. I love what you guys are up too. This sort of clever work and
    exposure! Keep up the excellent works guys I've you guys to my blogroll.
    Have a look at my blog How To Meet women on Facebook

    ReplyDelete
  2. Thanks very nice blog!
    Feel free to visit my site - acoustic guitars for sale

    ReplyDelete