是否有API函数来检查呼叫当前是否处于活动状态,或者是否已暂停?
假设我有两个已连接的呼叫,有没有办法检查每个呼叫是否处于活动状态,是否处于保持状态,还是可能已在电话会议中连接?
答案 0 :(得分:30)
是的,您可以检查呼叫是否在设备上处于活动状态:
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;
}
}
答案 1 :(得分:1)
这是正确的方法:
<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
文档:https://developer.android.com/reference/android/telecom/TelecomManager#isInCall()