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;
}
# 1 楼答案
我找到了适用于我的解决方案here。并添加了以下代码:
我调用
isExternalMicConnected()
,它会显示自定义麦克风是否已连接