There is a transparent code for determining the connection / disconnection of headphones, tell me how to determine if an external microphone is connected (presence of a microphone at the connected headset)
private class MusicIntentReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Intent.ACTION_HEADSET_PLUG)) { int state = intent.getIntExtra("state", -1); switch (state) { case 0: Log.d(TAG, "Headset is unplugged"); break; case 1: Log.d(TAG, "Headset is plugged"); break; default: Log.d(TAG, "I have no idea what the headset state is"); } } } IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG); registerReceiver(myReceiver, filter);