Example usage for android.media AudioManager ACTION_HEADSET_PLUG

List of usage examples for android.media AudioManager ACTION_HEADSET_PLUG

Introduction

In this page you can find the example usage for android.media AudioManager ACTION_HEADSET_PLUG.

Prototype

String ACTION_HEADSET_PLUG

To view the source code for android.media AudioManager ACTION_HEADSET_PLUG.

Click Source Link

Document

Broadcast Action: Wired Headset plugged in or unplugged.

Usage

From source file:Main.java

public static String getWiredHeadsetUpdateAction() {
    if (Build.VERSION.SDK_INT >= 21) {
        return AudioManager.ACTION_HEADSET_PLUG;
    } else {/*w ww  . j  av a  2s.  co  m*/
        return Intent.ACTION_HEADSET_PLUG;
    }
}

From source file:com.cyanogenmod.settings.otgtoggle.UsbDeviceMonitorService.java

@Override
public void onCreate() {
    super.onCreate();

    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    mUsbManager = (UsbManager) getSystemService(USB_SERVICE);

    mStateMachine = new UsbPortStateMachine(this);
    mStateMachine.setDbg(true); // XXX
    mStateMachine.start();/*from  w  ww  .j av a 2  s.c  o m*/

    IntentFilter filter = new IntentFilter();
    filter.addAction(AudioManager.ACTION_HEADSET_PLUG);
    filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
    filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
    registerReceiver(mDeviceStateReceiver, filter);
}