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.
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);
// 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);
}
}
}
}
};
I love what you guys are up too. This sort of clever work and
ReplyDeleteexposure! 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
Thanks very nice blog!
ReplyDeleteFeel free to visit my site - acoustic guitars for sale