How to check if a telephone call is currently active from a non-telephone app?
What API do I need to detect this?
"Ongoing" suggests that the call is currently in session, which has caused me to check my phone connection quite a few times to make sure that I do not have an open line.
We are able to make a phone call in android via intent. You need to write only three lines of code to make a phone call. Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:"+8802177690));//change the number.
We can also get the information of call state using the TelephonyManager class. For this purpose, we need to call the listen method of TelephonyManager class by passing the PhonStateListener instance. The PhoneStateListener interface must be implemented to get the call state.
try this:
public boolean isCallActive(Context context){
AudioManager manager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
return manager.getMode() == AudioManager.MODE_IN_CALL;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With