Android上连接的音频输入设备列表

时间:2014-05-21 07:58:00

标签: java android

我的应用程序必须仅从外部麦克风录制声音。有没有办法获得可用的麦克风列表?

我使用AudioRecord进行声音捕捉。

提前致谢。

1 个答案:

答案 0 :(得分:1)

适用于我的解决方案我发现here。并添加了以下代码:

private static boolean headsetMic;

private static BroadcastReceiver mReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        final String action = intent.getAction();
        if (Intent.ACTION_HEADSET_PLUG.equals(action)) {
            final int headphones = intent.getIntExtra("state", -1);
            final int mic = intent.getIntExtra("microphone", -1);
            // we need to check both of them, because if headset with
            // mic was disconnected mic is 1 but headphones is 0, and
            // actually no external mic is connected
            headsetMic = headphones > 0 && mic > 0;
        }
    }
};

public static boolean isExternalMicConnected() {
    return headsetMic;
}

我拨打isExternalMicConnected()并显示自定义麦克风是否已连接。