It works for me correctly:
if(context.registerReceiver(null, new IntentFilter(Intent.ACTION_HEADSET_PLUG)).getIntExtra("state", 0)==1){
//if(audioManager.isWiredHeadsetOn()){
System.out.println("Headset is wiredOn");
}
else{
System.out.println("Headset is not wiredOn");
}