How to add list of google contacts in cordova

199 views Asked by At

I have created an application in Cordova. It signs with the google and it displays name and email-id. Now i want to display all the contacts that are connected with the google. Can anyone explain me how can I do that?

Below is the code and screenshot of my application.

Thanks in advance.

<!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

There are 1 answers

0
abielita On

Have you checked on this ContactsPhoneNumbers plugin and/or cordova-plugin-contacts? It's a cross-platform plugin for Cordova/PhoneGap that lists all the contacts with at least a phone number. You may follow the tutorial on how to install and setup the plugin properly. Just make sure that you have cordova 5.0+ to make it work. Hope this helps!