I think once you start a call using Telephony service, the microphone will open regardless if the other side picks up your call or not, but if you really want you can use the AudioManager service like so.
AudioManager audioManager = (AudioManager) getSystemService(context);
// This is to get the active mode of the AudioManager
int mode = audioManager.getMode();
// use AudioManager.MODE_IN_CALL for audio call
// use AudioManager.MODE_IN_COMMUNICATION for audio/video chat or VOIP
if (AudioManager.MODE_IN_CALL == mode) {
// Enters here during active call.
}
Here is the full method.
public void listener(){
final AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
new Thread(new Runnable() {
@Override
public void run() {
while(true){
// This is to get the active mode of the AudioManager
int mode = audioManager.getMode();
// use AudioManager.MODE_IN_CALL for audio call
// use AudioManager.MODE_IN_COMMUNICATION for audio/video chat or VOIP
if (AudioManager.MODE_IN_COMMUNICATION == mode) {
// Enters here during active internet call.
Log.e(TAG, "In Internet Call (VOIP)");
}else if (AudioManager.MODE_IN_CALL == mode) {
// Enters here during active call.
Log.e(TAG, "In Normal Call");
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
}
Now just call the listener() method in your Class.
Read more about it Here on the developer documentation.