[ Cordova ] Get contact

[ Cordova ] Get contact

Hi everybody,

I'm a new user of intel XDK and i tried to do something simple as :

- get contacts in my phone

- display their display name

I arrived to do that I want in environment XDK but when i do a debug across my physical phone i have an error.

<!DOCTYPE html>

    <title>Using PhoneGap Audio Media</title>
    <meta content="text/html; charset=utf-8" http-equiv="Content-type">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
    <style type="text/css">
        /* Prevent copy paste for all elements except text fields */
        *  { -webkit-user-select:none; -webkit-tap-highlight-color:rgba(255, 255, 255, 0); }
        input, textarea  { -webkit-user-select:text; }
    <script type="text/javascript">
        /* This function runs once the page is loaded, but intel.xdk API is not yet active */
        var init = function(){


        /* This code prevents users from dragging/scrolling the page */
        var preventDefaultScroll = function(event) {
            return false;
        document.addEventListener('touchmove', preventDefaultScroll, false);

    <script src="appframework/appframework.ui.min.js" type="text/javascript"></script>

    <script src="intelxdk.js"></script>
    <script type="text/javascript">
        /* This code is used to run as soon as intel.xdk.device.ready is active */
        var onDeviceReady=function(){
        //hide splash screen
    <script src="cordova.js" type="text/javascript"></script>
    <script type="text/javascript">
        function onDeviceReady() {
            var options = new ContactFindOptions();
            var fields =  ["*"];               
            navigator.contacts.find(fields, onSuccess, onError);
            function onSuccess(contacts) {
                for (var i = 0; i < contacts.length; i++) {
                   document.write("<br>Display Name = " + contacts[i].displayName);
          function onError(contacts) {
                try {
                    for (var i = 0; i < contacts.length; i++) {
                   document.write("<br>Display Name = " + contacts[i]);
              catch (e){
                  console.log("<br>error "+e); 
       document.addEventListener("deviceready", onDeviceReady, false);

All time after calling navigator.contacts.find, I'm redirected to onError function and it seems that i have an error json.

Could you help me please

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Try the following script tag lines:

<script src="intelxdk.js"></script>
<script src="cordova.js"></script>


Leave a Comment

Please sign in to add a comment. Not a member? Join today