Frage

I was wondering if there was a way in to check where the audio is being played on (internal speaker, headphone jack, mono, stereo, etc.) and Android device?

Thanks.

War es hilfreich?

Lösung

Yes, using the AudioManager class it's possible for you to check if a wired or wireless headset is currently connected. If it's not, then you can assume that the sounds you emit will be played out by the device's speakers.

These are the methods will help you accomplish what you're trying to do :

Hope this answers your question !

Andere Tipps

The accepted answer will totally work but they did deprecate those methods in favor of audioManager.getDevices(). Here's an example of how how you could check for a wired headset using the new method.

AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
    if (audioManager != null) {
        for(AudioDeviceInfo deviceInfo : audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS)){
            if(deviceInfo.getType()==AudioDeviceInfo.TYPE_WIRED_HEADPHONES
                    || deviceInfo.getType()==AudioDeviceInfo.TYPE_WIRED_HEADSET){
                return true;
            }
        }
    }

Now keep in mind that getDevices() is only available in API 23+ so there is a gap in coverage and you may need to use the deprecated methods shown in the accepted answer if your minSdk is below 23.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top