[android] headphone plug

public class MainService extends Service
{
  @Override
  public void onCreate()
  {
    super.onCreate();
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_HEADSET_PLUG);
    registerReceiver(receiver, filter);
  }
  
  
  @Override
  public void onDestroy()
  {
    super.onDestroy();
    unregisterReceiver(receiver);
  }
  
  private BroadcastReceiver receiver = new BroadcastReceiver()
  {
    @Override
    public void onReceive(Context context, Intent $intent)
    {
      int state = $intent.getIntExtra("state", 0);
      String name = $intent.getStringExtra("name");
      int hasMic = $intent.getIntExtra("microphone", 0);
      Log.i("MainService.java | onReceive", "state : " + state + "(0:unplugged, 1:plugged)" + "\nname : " + name + "\nhas MIC : " + hasMic + "(1:has microphone)");
    }
  };
}

 

state : 1(0:unplugged, 1:plugged)
name : h2w
has MIC : 0(1:has microphone)