Is there an API function to check if a call is currently Active, or if has been put on Hold?
Assuming I have two connected calls, is there a way to check if each one is active, on-hold, or maybe they are connected in a conference call?
Yes, you can check if a call is active over device or not:
public static boolean isCallActive(Context context){
AudioManager manager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
if(manager.getMode()==AudioManager.MODE_IN_CALL){
return true;
}
else{
return false;
}
}
This is proper way:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
private boolean runThisWhileStartingApp() {
boolean hasPhonePermission = checkPermission(android.Manifest.permission.READ_PHONE_STATE, "Explantation why the app needs this permission");
if (!hasPhonePermission) {
// user did not allow READ_PHONE_STATE permission
}
}
private boolean checkPermission(final String permissionName, String reason) {
if (ContextCompat.checkSelfPermission(MyActivity.this, permissionName) != android.content.pm.PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(MyActivity.this, permissionName)) {
AlertDialog alertDialog = new AlertDialog.Builder(MyActivity.this).create();
alertDialog.setTitle(permissionName);
alertDialog.setMessage(reason);
alertDialog.setCancelable(false);
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
ActivityCompat.requestPermissions(MyActivity.this, new String[]{ permissionName }, 1000);
}
});
alertDialog.show();
} else {
ActivityCompat.requestPermissions(InitActivity.this, new String[]{ permissionName }, 1000);
}
return false;
}
return true;
}
TelecomManager tm = (TelecomManager) getSystemService(Context.TELECOM_SERVICE);
boolean isInCall = tm.isInCall(); // true if there is an ongoing call in either a managed or self-managed ConnectionService, false otherwise
Documentation: https://developer.android.com/reference/android/telecom/TelecomManager#isInCall()
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