获取音频输入设备
AudioManager mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); AudioDeviceInfo[] infos = mAudioManager.getDevices(AudioManager.GET_DEVICES_INPUTS);
获取音频输出设备
AudioManager mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); AudioDeviceInfo[] infos = mAudioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS);
AudioDeviceInfo对象就是包含了相关信息,可以通过一下方法进行判断
相关常量
android.media.AudioDeviceInfo
/**
* A device type associated with an unknown or uninitialized device.
*/
public static final int TYPE_UNKNOWN = 0;
/**
* A device type describing the attached earphone speaker.
*/
public static final int TYPE_BUILTIN_EARPIECE = 1;
/**
* A device type describing the speaker system (i.e. a mono speaker or stereo speakers) built
* in a device.
*/
public static final int TYPE_BUILTIN_SPEAKER = 2;
/**
* A device type describing a headset, which is the combination of a headphones and microphone.
*/
public static final int TYPE_WIRED_HEADSET = 3;
/**
* A device type describing a pair of wired headphones.
*/
public static final int TYPE_WIRED_HEADPHONES = 4;
/**
* A device type describing an analog line-level connection.
*/
public static final int TYPE_LINE_ANALOG = 5;
/**
* A device type describing a digital line connection (e.g. SPDIF).
*/
public static final int TYPE_LINE_DIGITAL = 6;
/**
* A device type describing a Bluetooth device typically used for telephony.
*/
public static final int TYPE_BLUETOOTH_SCO = 7;
/**
* A device type describing a Bluetooth device supporting the A2DP profile.
*/
public static final int TYPE_BLUETOOTH_A2DP = 8;
/**
* A device type describing an HDMI connection .
*/
public static final int TYPE_HDMI = 9;
/**
* A device type describing the Audio Return Channel of an HDMI connection.
*/
public static final int TYPE_HDMI_ARC = 10;
/**
* A device type describing a USB audio device.
*/
public static final int TYPE_USB_DEVICE = 11;
/**
* A device type describing a USB audio device in accessory mode.
*/
public static final int TYPE_USB_ACCESSORY = 12;
/**
* A device type describing the audio device associated with a dock.
*/
public static final int TYPE_DOCK = 13;
/**
* A device type associated with the transmission of audio signals over FM.
*/
public static final int TYPE_FM = 14;
/**
* A device type describing the microphone(s) built in a device.
*/
public static final int TYPE_BUILTIN_MIC = 15;
/**
* A device type for accessing the audio content transmitted over FM.
*/
public static final int TYPE_FM_TUNER = 16;
/**
* A device type for accessing the audio content transmitted over the TV tuner system.
*/
public static final int TYPE_TV_TUNER = 17;
/**
* A device type describing the transmission of audio signals over the telephony network.
*/
public static final int TYPE_TELEPHONY = 18;
/**
* A device type describing the auxiliary line-level connectors.
*/
public static final int TYPE_AUX_LINE = 19;
/**
* A device type connected over IP.
*/
public static final int TYPE_IP = 20;
/**
* A type-agnostic device used for communication with external audio systems
*/
public static final int TYPE_BUS = 21;
/**
* A device type describing a USB audio headset.
*/
public static final int TYPE_USB_HEADSET = 22;
/**
* A device type describing a Hearing Aid.
*/
public static final int TYPE_HEARING_AID = 23;
/**
* A device type describing the speaker system (i.e. a mono speaker or stereo speakers) built
* in a device, that is specifically tuned for outputting sounds like notifications and alarms
* (i.e. sounds the user couldn't necessarily anticipate).
* Note that this physical audio device may be the same as {@link #TYPE_BUILTIN_SPEAKER}
* but is driven differently to safely accommodate the different use case.
*/
public static final int TYPE_BUILTIN_SPEAKER_SAFE = 24;
/**
* @hide
* A device type for rerouting audio within the Android framework between mixes and
* system applications. Typically created when using
* {@link android.media.audiopolicy.AudioPolicy} for mixes created with the
* {@link android.media.audiopolicy.AudioMix#ROUTE_FLAG_RENDER} flag.
*/
@SystemApi
public static final int TYPE_REMOTE_SUBMIX = 25;