I'm really new to DrupalGap and PhoneGap. I have a question, how can we access the phone contacts in DrupalGap? I want to list the mobile numbers and other contact details in the application. Then select some of the contacts and store in the Drupal database.
The steps I followed:
- Installed PhoneGap
- Created PhoneGap project
- Contacts pulgin installed for the project
- Copied the DrupalGap to the www folder of the project
- Done the necessary settings changes
- Created a custom module to access the contacts from PhoneGap in laptop
I found some code snippet to access the contacts in PhoneGap as follows:
function sync_contacts_get_contacts() {
// specify contact search criteria
var options = new ContactFindOptions();
options.filter = ""; // empty search string returns all contacts
options.multiple = true; // return multiple results
filter = ["displayName"]; // return contact.displayName field
// find contacts
navigator.contacts.find(filter, onSuccess, onError, options);
}
function onSuccess(contacts) {
for (var i=0; i<contacts.length; i++) {
if (contacts[i].displayName) { // many contacts don't have displayName
alert(contacts[i].displayName);
}
}
};
// onError: Failed to get the contacts
//
function onError(contactError) {
alert('onError!');
}
How can I access this in DrupalGap module I created and store in Drual database?
SOLUTION:
Later in my research I realized one of my misunderstanding. Contacts, camera etc. are work only in device. That means "navigator.contacts" cannot test in the web browser. we have to build the .apk file and install that in the device and test.
Instead of writing the contacts getting code, we can use the PhoneGap plugin from this location: https://github.com/dbaq/cordova-plugin-contacts-phone-numbers.
Using the custom service I stored the contacts in Drupal database. Link: http://docs.drupalgap.org/7/Services/Create_a_Custom_Service
To create the .apk file we have to follow the URL: http://docs.drupalgap.org/7/Compiling_a_Mobile_Application/Preparing_PhoneGap/Installing_PhoneGap/index