I used the below added code to get the connected audio devices for android device. Used AudioManager api method getDevices()
and got the result with connected devices like earphones, speaker, headphones. But this getDevices()
method is available since android api level 23 (Marshmallow) only.
But my application should support from api level 21 (Lollipop). Please can anybody let me know the alternative api to get the available audio device for the android device.
Code used with api level 23.
AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
AudioDeviceInfo[] adi = audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS);
}
Please help me by providing a way to get the connected audio devices for the devices running with Android OS version below Marshmallow(api level 23).