Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telephony is optional #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<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"/>
<uses-feature android:name="android.hardware.telephony" android:required="false" />
</config-file>
<config-file parent="/manifest/application" target="AndroidManifest.xml">
<service android:name="com.dmarc.cordovacall.MyConnectionService"
Expand Down
37 changes: 26 additions & 11 deletions src/android/CordovaCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class CordovaCall extends CordovaPlugin {
private String from;
private String to;
private String realCallTo;
private Boolean hasTelephony = false;
private static HashMap<String, ArrayList<CallbackContext>> callbackContextMap = new HashMap<String, ArrayList<CallbackContext>>();
private static CordovaInterface cordovaInterface;
private static Icon icon;
Expand All @@ -64,17 +65,23 @@ 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);
}
if(android.os.Build.VERSION.SDK_INT >= 23) {
phoneAccount = new PhoneAccount.Builder(handle, appName)
.setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER)
.build();
tm.registerPhoneAccount(phoneAccount);

PackageManager mgr = this.cordova.getActivity().getApplicationContext().getPackageManager();
hasTelephony = mgr.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);

if (hasTelephony) {
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)
.build();
tm.registerPhoneAccount(phoneAccount);
}
}
callbackContextMap.put("answer",new ArrayList<CallbackContext>());
callbackContextMap.put("reject",new ArrayList<CallbackContext>());
Expand Down Expand Up @@ -214,6 +221,10 @@ public void run() {
this.callbackContext.success("Speakerphone is off");
return true;
} else if (action.equals("callNumber")) {
if (!hasTelephony) {
this.callbackContext.error("Telephony is not supported by device");
return true;
}
realCallTo = args.getString(0);
if(realCallTo != null) {
cordova.getThreadPool().execute(new Runnable() {
Expand Down Expand Up @@ -261,6 +272,10 @@ private void receiveCall() {
}

private void sendCall() {
if (!hasTelephony) {
this.callbackContext.error("Telephony is not supported by device");
return;
}
Uri uri = Uri.fromParts("tel", to, null);
Bundle callInfoBundle = new Bundle();
callInfoBundle.putString("to",to);
Expand Down