javascriptcordovacordova-pluginscall

What is the best way to get call duration in Cordova?


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);

Solution

  • 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