diff --git a/plugin.xml b/plugin.xml index 4ec73a5..ca540e9 100644 --- a/plugin.xml +++ b/plugin.xml @@ -19,14 +19,14 @@ - + android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE" + android:exported="true"> diff --git a/src/android/CordovaCall.java b/src/android/CordovaCall.java index 53dbd95..a3f5e1d 100644 --- a/src/android/CordovaCall.java +++ b/src/android/CordovaCall.java @@ -75,12 +75,14 @@ public void initialize(CordovaInterface cordova, CordovaWebView webView) { appName = getApplicationName(this.cordova.getActivity().getApplicationContext()); handle = new PhoneAccountHandle(new ComponentName(this.cordova.getActivity().getApplicationContext(),MyConnectionService.class),appName); tm = (TelecomManager)this.cordova.getActivity().getApplicationContext().getSystemService(this.cordova.getActivity().getApplicationContext().TELECOM_SERVICE); - if(android.os.Build.VERSION.SDK_INT >= 26) { - phoneAccount = new PhoneAccount.Builder(handle, appName) - .setCapabilities(PhoneAccount.CAPABILITY_SELF_MANAGED) - .build(); - tm.registerPhoneAccount(phoneAccount); - } + // Removing fixes java.lang.IllegalArgumentException: Error, cannot change a self-managed phone account + // We do not want SELF_MANAGED as we want to use the default phone app + // if(android.os.Build.VERSION.SDK_INT >= 26) { + // phoneAccount = new PhoneAccount.Builder(handle, appName) + // .setCapabilities(PhoneAccount.CAPABILITY_SELF_MANAGED) + // .build(); + // tm.registerPhoneAccount(phoneAccount); + // } if(android.os.Build.VERSION.SDK_INT >= 23) { phoneAccount = new PhoneAccount.Builder(handle, appName) .setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER) @@ -271,6 +273,9 @@ private void receiveCall() { tm.addNewIncomingCall(handle, callInfo); permissionCounter = 0; this.callbackContext.success("Incoming call successful"); + + this.bringAppToFront(); + this.tm.showInCallScreen(true); } private void sendCall() { @@ -286,6 +291,13 @@ private void sendCall() { this.callbackContext.success("Outgoing call successful"); } + private void bringAppToFront() { + Intent intent = new Intent(this.cordova.getActivity().getApplicationContext(), this.cordova.getActivity().getClass()); + // Intent.FLAG_ACTIVITY_REORDER_TO_FRONT Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_FROM_BACKGROUND); + this.cordova.getActivity().getApplicationContext().startActivity(intent); + } + private void mute() { AudioManager audioManager = (AudioManager) this.cordova.getActivity().getApplicationContext().getSystemService(Context.AUDIO_SERVICE); audioManager.setMicrophoneMute(true);