La llamada no funciona en Android usando Cordova, tomando contactos del teléfono

I want to call a phone number from clicking on a link, but the contact should be retrieved from phone. So I implemented a code for this. But tel is opening dialer, but my retrieved contact number is missing. Any suggestion?

<!DOCTYPE html>
    <title>Contact Example</title>
    <script type="text/javascript" charset="utf-8" src="cordova-1.8.0.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="" />
    <script src="jquery-1.7.1.min.js"></script>
    <script src=""></script>
    <script type="text/javascript" charset="utf-8">

    // Wait for Cordova to load
    document.addEventListener("deviceready", onDeviceReady, false);

    // Cordova is ready
    function onDeviceReady() {
        // specify contact search criteria
        var options = new ContactFindOptions();
        options.filter="";          // empty search string returns all contacts
        options.multiple=true;      // return multiple results
        filter = ["displayName"];   // return contact.displayName field

        // find contacts
        navigator.contacts.find(filter, onSuccess, onError, options);

    // onSuccess: Get a snapshot of the current contacts
    function onSuccess(contacts) {
        for (var i=0; i<contacts.length; i++) {
            var phonenumber;
            phonenumber = contacts[i].phoneNumbers;
            $("ul").append("<li><a href=tel:"+phonenumber+">"+contacts[i].displayName+"</a></li>");

    // onError: Failed to get the contacts
    function onError(contactError) {

    <ul data-role="listview" data-theme="g" data-filter="true">

preguntado el 12 de junio de 12 a las 10:06

3 Respuestas

contacts[i].phoneNumbers is an array, so you should add it the variable:

var phonenumber = contacts[i].phoneNumbers[0];

or loop through that array, which ever suits you best.

Respondido el 12 de junio de 12 a las 11:06

Also, you should double check that contacts[i].phoneNumbers is not null which it will be if the contact has no phone numbers. - Simón MacDonald

Your filter is wrong. You need to make it: filter = ["displayName", "phoneNumbers"]; this will return an array of contacts with their displayName and phoneNumbers populated. - Simón MacDonald

Prueba con

$("ul").append("<li><a href=callto:"+phonenumber+">"+contacts[i].displayName+"</a></li>");

Respondido el 12 de junio de 12 a las 13:06

Esto funcionó para mí:

phonenumber = contacts[i].phoneNumbers[0].value.replace(" ", "");

$("#ul").append("<li><a href=tel:+91"+phonenumber.replace(" ", "")+">"+contacts[i].displayName+"<br/>"+phonenumber.replace(" ", "")+"</a></li><br/>");

I used replace() function because i am getting space in between the digits of phone number.

Espero que te ayude.

Respondido 29 Abr '14, 07:04

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.