Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
</config-file>

<config-file parent="/*" target="AndroidManifest.xml">
<uses-permission android:name="android.permission.BIND_TELECOM_CONNECTION_SERVICE"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.MANAGE_OWN_CALLS"/>
</config-file>

<config-file parent="/manifest/application" target="AndroidManifest.xml">
<service android:name="com.dmarc.cordovacall.MyConnectionService"
android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE">
android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE"
android:exported="true">
<intent-filter>
<action android:name="android.telecom.ConnectionService" />
</intent-filter>
Expand Down
24 changes: 18 additions & 6 deletions src/android/CordovaCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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() {
Expand All @@ -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);
Expand Down