4
Licensed to the Apache Software Foundation (ASF) under one
5
or more contributor license agreements. See the NOTICE file
6
distributed with this work for additional information
7
regarding copyright ownership. The ASF licenses this file
8
to you under the Apache License, Version 2.0 (the
9
"License"); you may not use this file except in compliance
10
with the License. You may obtain a copy of the License at
12
http://www.apache.org/licenses/LICENSE-2.0
14
Unless required by applicable law or agreed to in writing,
15
software distributed under the License is distributed on an
16
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17
KIND, either express or implied. See the License for the
18
specific language governing permissions and limitations
26
<meta name="viewport" content="width=device-width,height=device-height,user-scalable=no,maximum-scale=1.0,initial-scale=1.0" />
27
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> <!-- ISO-8859-1 -->
28
<title>Cordova Mobile Spec</title>
29
<link rel="stylesheet" href="../master.css" type="text/css" media="screen" title="no title" charset="utf-8">
30
<script type="text/javascript" charset="utf-8" src="../cordova-incl.js"></script>
33
<script type="text/javascript" charset="utf-8">
35
var deviceReady = false;
37
//-------------------------------------------------------------------------
39
//-------------------------------------------------------------------------
40
function getContacts() {
41
obj = new ContactFindOptions();
42
// show all contacts, so don't filter
44
navigator.contacts.find(
45
["displayName", "name", "phoneNumbers", "emails", "urls", "note"],
48
if (contacts.length == 0) {
49
s = "No contacts found";
52
s = "Number of contacts: "+contacts.length+"<br><table width='100%'><tr><th>Name</th><td>Phone</td><td>Email</td></tr>";
53
for (var i=0; i<contacts.length; i++) {
54
var contact = contacts[i];
55
s = s + "<tr><td>" + contact.name.formatted + "</td><td>";
56
if (contact.phoneNumbers && contact.phoneNumbers.length > 0) {
57
s = s + contact.phoneNumbers[0].value;
60
if (contact.emails && contact.emails.length > 0) {
61
s = s + contact.emails[0].value;
67
document.getElementById('contacts_results').innerHTML = s;
70
document.getElementById('contacts_results').innerHTML = "Error: "+e.code;
75
function addContact(){
76
console.log("addContact()");
78
var contact = navigator.contacts.create({"displayName": "Dooney Evans"});
80
formatted: "Dooney Evans",
86
contact.name = contactName;
88
var phoneNumbers = [1];
89
phoneNumbers[0] = new ContactField('work', '512-555-1234', true);
90
contact.phoneNumbers = phoneNumbers;
93
function() { alert("Contact saved.");},
94
function(e) { alert("Contact save failed: " + e.code); }
96
console.log("you have saved the contact");
105
* Function called when page has finished loading.
108
document.addEventListener("deviceready", function() {
110
console.log("Device="+device.platform+" "+device.version);
112
window.setTimeout(function() {
114
alert("Error: Apache Cordova did not initialize. Demo will not run correctly.");
122
<body onload="init();" id="stage" class="theme">
127
<span id="contacts_results"> </span>
130
<div class="btn large" onclick="getContacts();">Get phone's contacts</div>
131
<div class="btn large" onclick="addContact();">Add a new contact 'Dooney Evans'</div>
132
<h2> </h2><div class="backBtn" onclick="backHome();">Back</div>