英特尔XDK:无法读取Android手机中的联系人列表

时间:2014-10-13 06:51:44

标签: intel-xdk

我正在尝试阅读电话簿中的联系人。它在模拟器中工作正常。但是当我构建它并部署到手机时,这并没有显示任何内容。 我已经给了它联系人权限。 我做错了什么吗? 这是我的代码:



/** 
 * This function runs once the page is loaded, but intel is not yet active 
 */

var windowHeight;
var init = function () {
    windowHeight=window.innerHeight;
};

window.addEventListener("load", init, false);  

/**
 * Prevent Default Scrolling 
 */
preventDefaultScroll = function(event) 
{
    // Prevent scrolling on this element
    event.preventDefault();
    window.scroll(0,0);
    return false;
};
    
window.document.addEventListener("touchmove", preventDefaultScroll, false);

/**
 * Device Ready Code 
 * This event handler is fired once the JavaScript bridge library is ready
 */
function onDeviceReady()
{
    //lock orientation
    intel.xdk.device.setRotateOrientation("portrait");
    intel.xdk.device.setAutoRotate(false);
        
    //manage power
    intel.xdk.device.managePower(true,false);

    //hide splash screen
    intel.xdk.device.hideSplashScreen();
    intel.xdk.contacts.getContacts();
}
    
document.addEventListener("intel.xdk.device.ready",onDeviceReady,false); 
   
//Event listener for contacts
document.addEventListener('intel.xdk.contacts.get', contactsReceived, false);

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

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

    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);
    }
}
&#13;
<!DOCTYPE html><!--HTML5 doctype-->
<html>
    <head>
        <script>
            (function() {
                if ("-ms-user-select" in document.documentElement.style && navigator.userAgent.match(/IEMobile\/10\.0/)) 
                {
                    var msViewportStyle = document.createElement("style");
                    msViewportStyle.appendChild(document.createTextNode("@-ms-viewport{width:auto!important}"));
                    document.getElementsByTagName("head")[0].appendChild(msViewportStyle);
                }
            })();
        </script>
        <title>Contactos</title>
        <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">
        <link href="css/fonts.css" rel="stylesheet" type="text/css" charset="utf-8" />
        <link href="css/main.css" rel="stylesheet" type="text/css">
        <script src="intelxdk.js"></script>
        <script src="main.js" type="text/javascript"></script>
    </head>
    
    <body>
        <div class="content" id="contentid">
            <table id="contact_list">
                
            </table>
        </div>
    </body>
</html>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

我相信最新版本的App Preview 2.4.0以及内置应用程序已经解决了这个问题,至少它现在对我有用。请试一试!