0

I am not able to get contacts list.

HTML Code:

<!DOCTYPE html><!--HTML5 doctype-->
<html>
<head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <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; }
        body { background-color:green; color:black }
    </style>
    <script src='intelxdk.js'></script>
    <script type="text/javascript">
        /* This code is used to run as soon as Intel activates */
        var onDeviceReady=function(){
        //hide splash screen
          intel.xdk.device.hideSplashScreen();
        };
        document.addEventListener("intel.xdk.device.ready",onDeviceReady,false);
    </script>
</head>
<body>
    <script>
        document.addEventListener('intel.xdk.contacts.get', contactsReceived, true);

        function contactsReceived() {

            alert("contacts recieved");

            var table = document.getElementById("contacts");
            table.innerHTML = '';

            var myContacts = intel.xdk.contacts.getContactList();

            alert("Contacts length: "+myContacts.length);
        }
    </script>
</body>
</html>

intel.xdk.contacts.get event is not fired. Is it a bug ?

4

2 回答 2

0

嗨,我遇到了同样的问题。但是我可以在部署(Sony xperia ion)后在电话中获得联系人。这是我的代码。我设置了联系人的权限。

<!DOCTYPE html>
<html><!--HTML5 doctype-->
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta http-equiv="Pragma" content="no-cache">
<script src="intelxdk.js"></script>
<!-- phantom library, needed for XDK api calls -->
<script src="cordova.js"></script>
<!-- phantom library, needed for Cordova api calls -->
<script src="xhr.js"></script>
<!-- phantom library, needed for XDK CORS -->
<script type="text/javascript" language="javascript">
    var onDeviceReady = function () {                 // called when Cordova is ready
      if (window.Cordova && navigator.splashscreen) { // Cordova API detected
        navigator.splashscreen.hide();                // hide splash screen
      }
      setTimeout(function () {
        $.ui.launch();
      }, 50);
		intel.xdk.contacts.getContacts();
    };
    document.addEventListener("deviceready", onDeviceReady, false);
</script>
<script src="js/appframework.ui.min.js"></script>
<script>
    if (isIntel)
      $.ui.autoLaunch = false;
    $.ui.useOSThemes = true; //Change this to false to force a device theme
    $.ui.blockPageScroll();
    $(document).ready(function () {
      if ($.ui.useOSThemes && (!$.os.ios || $.os.ios7))
        $("#afui").removeClass("ios");
    });
	
	document.addEventListener('intel.xdk.contacts.get', contactsReceived, false);

function contactsReceived() {
        var table = document.getElementById("contacts");
        table.innerHTML = '';

        var myContacts = intel.xdk.contacts.getContactList();
		if(myContacts.length==0)
		{
			alert("No contact found");
		}
        for(var i=0;i<myContacts.length;i++) {
                //add row to table
                var contactInfo = intel.xdk.contacts.getContactData(myContacts[i]);
                var tr = document.createElement("tr");
                tr.setAttribute('id', 'pnid'+contactInfo.id);
                tr.setAttribute('onClick', 'document.getElementById("iden").value = '+contactInfo.id+';');
                tr.setAttribute('style', 'background-color:#B8BFD8');
                var id = document.createElement("td");
                id.innerHTML = contactInfo.id;
                tr.appendChild(id);
                var msg = document.createElement("td");
                msg.innerHTML = contactInfo.name;
                tr.appendChild(msg);
                table.appendChild(tr);
        }
}
</script>
<link href="css/icons.css" rel="stylesheet" type="text/css">
<link href="css/af.ui.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="afui" class="ios">
    <div id="header" class="header"></div>
    <div id="content" style="">
        <div class="panel" title="Main" data-nav="nav_0" id="main" selected="selected"
        style="">
            <a class="button" href="#" style="" data-appbuilder-object="button" onclick="contactsReceived();">Hello World</a>
			<table id="contacts">
               
            </table>
        </div>
    </div>
    <div id="navbar" class="footer">
        <a href="#main" class="icon home">Home</a>
    </div>
    <header id="header_0" data-appbuilder-object="header">
        <a id="backButton" href="#" class="button backButton" style="visibility: visible; ">Back</a>
        <h1 id="pageTitle" class="">test</h1>
    </header>
    <nav id="nav_0" data-appbuilder-object="nav">
        <h1>Side Menu</h1>
    </nav>
</div>
</body>





</html>

于 2014-10-09T08:23:00.540 回答
0

我没有intel.xdk.contacts.getContacts()在里面打电话onDeviceReady从这里的帖子中找到这个。

于 2014-02-25T09:23:47.967 回答