Before Android 8.0, Oreo, you could detect a headset plugged in with a background service with a registered broadcast. With Android O's background execution limits, you can no longer do this without a notification.
While ACTION_HEADSET_PLUG is an excepted broadcast, it still doesn't send to Manifest registered receivers.
So you cannot use a background service. And you cannot be woken up via a manifest receiver. What's the solution? Never update your targetSDKVersion?