Check wether headphones are plugged in on Android device

Hello!

Is there a way to check if the device is currently using a headset, headphones? I want to adjust the audio by knowing if they are currently used because there’s much diference hearing a lower bass or some sounds with a headset, to not hearing that sounds at all without them

I just found it xD

It was in GearVR → Are Head Phones Plugged In

But this isn’t working right now in Android 23, i’m not using any GearVR however this should have to work anyway

I would also like to know if detected headphone is possible.
This would help greatly. I Tested Boscox reply and even with gearvr it wasnt working.

I want it working with or without vr.