MUI 获取手机中的联系人来生成电话簿

在html5下利用Native.js来获取系统通讯录管理对象AddressBook,再调用对象中的find()方法查找出系统通信录中的所有联系人。 
API:http://www.html5plus.org/doc/zh_cn/contacts.html#plus.contacts.AddressBook 
代码:

<!doctype html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
        <link href="../../css/mui.min.css" rel="stylesheet" />
        <style>

        </style>
    </head>
    <body>
        <header class="mui-bar mui-bar-nav">
            <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
            <h1 class="mui-title">联系人</h1>
        </header>
        <div class="mui-content">
            <ul class="mui-table-view" id="listArea">
                <li class="mui-table-view-cell" id="mode">
                    #
                </li>
            </ul>
        </div>
        <script src="../../js/mui.min.js"></script>
        <script type="text/javascript">
            mui.init();
                mui.plusReady(function() {
                    // 扩展API加载完毕,现在可以正常调用扩展API
                    plus.contacts.getAddressBook(plus.contacts.ADDRESSBOOK_PHONE, function(addressbook) {
                        addressbook.find(["displayName", "phoneNumbers"], function(contacts) {
                            for(var i = 0, len = contacts.length; i < len; i++) {
                                var li = document.getElementById("mode").cloneNode(true);
                                li.innerHTML = contacts[i].displayName + "<br/>手机:" + (contacts[i].phoneNumbers.length == 0 ? "" : contacts[i].phoneNumbers[0].value);
                                document.getElementById("listArea").appendChild(li);
                            }
                        }, function() {
                            mui.toast("获取电话簿失败 ");
                        }, {
                            multiple: true
                        });
                    }, function(e) {
                        mui.toast("获取电话簿失败 " + e.message);
                    });
                });

        </script>
    </body>

</html>
posted @ 2018-04-27 09:30  zero_1  阅读(245)  评论(0编辑  收藏  举报