I don't know that this is SDK-specific, since it's true even of the sounds on the Launcher screen. but FWIW:
No sound comes out of (wired of course) headphones until the user makes a manual change to the volume (by either method). Or exits to the Launcher, or sleeps and re-wakes. (Launching an app, in theory, is a reboot—but does not activate audio. Only exiting an app will.)
And when you remove the headphones, vice versa: no sound from the internal speaker until you take one of those actions.
If it's not practical to poll for headphone insertion/removal all the time, then maybe every 2 seconds or something? Or if not that, what about this... check a) every time the user moves up/down the Launcher, b) every time any app is launched, and c) every time the System menu is opened (so toggling that button would detect headphones without fiddling with volume.)