Time for action – searching device contacts
We will now see an example of getting all the contacts from the device and listing them down:
- Create a new project using the PhoneGap CLI:
$ phonegap create ContactsApi
- Change the current working directory to the directory that is newly created:
$ cd ContactsApi
- Add the required platforms to the project. We will add Android for this example:
$ phonegap platform add android
- Install the Contacts plugin to the project:
$ phonegap plugin add cordova-plugin-contacts
- In the
www/index.html
file, you need to replace the content and add the following code. To start with, let's create an event listener and bind that to a function. In the following code, when the device is ready, theOnDeviceReady
method will be fired:<script type=”text/javascript” charset=”utf-8”> document.addEventListener(“deviceready”, onDeviceReady, false); </script>
- Now, let's add the content for the
OnDeviceReady
...