skip to Main Content

I’m working on a Cordova application that needs to access information about phone calls. I need to know how long a call lasted to record this information in my application.

I have searched Cordova documentation and internet forums, but I couldn’t find any clear information on how to access call duration in Cordova.

Is there any way to get call duration in Cordova? If so, how can I do it? Thank you in advance for your help

I tray this, but not success:

 function onSuccess(result) {
    console.log('Call started');
    var startTime = new Date();
    document.addEventListener("deviceready", function () {
        window.plugins.callNumber.onCallStateChanged(function (state) {
            if (state == "DISCONNECTED") {
                var endTime = new Date();
                var duration = endTime - startTime;
                console.log('Call ended, duração: ' + duration + 'ms');
            }
        });
    });
    console.log("Success:" + result);
}

function onError(result) {
    console.log("Error:" + result);
}

window.plugins.CallNumber.callNumber(onSuccess, onError, number);

2

Answers


  1. Chosen as BEST ANSWER

    Solved with successfull:

    function onDeviceReady() {
    
      window.plugins.callLog.requestReadPermission((ev) => {
        console.log(ev)
        if (ev == 'OK') {
          let filters = [{
            "name": "number",
            "value": "%99973%",
            "operator": "like",
          }];
          window.plugins.callLog.getCallLog(filters, function (data) {
            console.log('info kay:', data);
          }, function (ev) {
            console.log('Errror112:', ev);
          });
        }
      })
    
    }
    
    document.addEventListener('deviceready', onDeviceReady, false);
    
    
    

  2. You’re not using the right plugin. Give a try to https://github.com/creacore-team/cordova-plugin-calllog

    Android only Cordova plugin to access the call history on a device.
    Results can be filtered through several parameters

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search