CFCallNumber.java
1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package mx.ferreyra.callnumber;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.telephony.TelephonyManager;
public class CFCallNumber extends CordovaPlugin
{
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
String number = args.getString(0);
String crmID = args.getString(1);
com.flexydial.app.CallRecordingService.calledNum=number;
com.flexydial.app.CallRecordingService.calledCRM=crmID;
if( number.startsWith("tel:") == false){
number = String.format("tel:%s", number);
}
try {
Intent intent = new Intent(isTelephonyEnabled() ? Intent.ACTION_CALL : Intent.ACTION_VIEW);
intent.setData(Uri.parse(number));
cordova.getActivity().startActivity(intent);
callbackContext.success();
}
catch (Exception e) {
callbackContext.error("CouldNotCallPhoneNumber");
}
return true;
}
private boolean isTelephonyEnabled(){
TelephonyManager tm = (TelephonyManager)cordova.getActivity().getSystemService(Context.TELEPHONY_SERVICE);
return tm != null && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE;
}
}