如何在cordova

时间:2016-12-22 14:41:01

标签: cordova google-api google-contacts

我在Cordova中创建了一个应用程序。它与谷歌签约,它显示名称和电子邮件ID。现在我想显示与谷歌连接的所有联系人。谁能解释我怎么能这样做?

以下是我的应用程序的代码和屏幕截图。

提前致谢。

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta name="format-detection" content="telephone=no"/>
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height"/>
    <link rel="stylesheet" type="text/css" href="css/index.css"/>
    <meta name="msapplication-tap-highlight" content="no"/>
    <title>Hello World</title>
</head>
<body>
<div class="app">
    <img id="image" style="position:absolute; top:10px; left:10px" src="" />

    <h1>Google+</h1>

    <div id="deviceready" >
        <p class="event listening">Connecting to Device</p>
        <p class="event received">Device is Ready</p>
        <p id="feedback">not logged in</p>
        <button onclick="login()">Login with Google+</button>
        <br/><br/>

        <button onclick="logout()">Logout</button>
        <br/><br/>
        <br><br>
        <button onclick="window.location.href='RegistrationForm.html'">Reguster</button>
    </div>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript" src="GoogleContacts.js"></script>
<script type="text/javascript">
  app.initialize();
  function isAvailable() {
    window.plugins.googleplus.isAvailable(function(avail) {alert(avail)});
  }
  function login() {
    window.plugins.googleplus.login(
        {},
        function (obj) {
          document.querySelector("#image").style.visibility = 'visible';
          document.querySelector("#feedback").innerHTML = "Hi, " + obj.displayName + ", " + obj.email;

        },
        function (msg) {
          document.querySelector("#feedback").innerHTML = "error: " + msg;
        }
    );
  }

  function logout() {
    window.plugins.googleplus.logout(
        function (msg) {
          document.querySelector("#image").style.visibility = 'hidden';
          document.querySelector("#feedback").innerHTML = msg;
        },
        function (msg) {
          document.querySelector("#feedback").innerHTML = msg;
        }
    );
  }
  window.onerror = function(what, line, file) {
    alert(what + '; ' + line + '; ' + file);
  };
  function handleOpenURL (url) {
    document.querySelector("#feedback").innerHTML = "App was opened by URL: " + url;
  }
</script>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

您是否已查看此ContactsPhoneNumbers plugin和/或cordova-plugin-contacts?它是Cordova / PhoneGap的跨平台插件,列出了至少包含电话号码的所有联系人。您可以按照教程了解如何正确安装和设置插件。只需确保您拥有Cordova 5.0+以使其正常工作。希望这有帮助!