2012-02-14 49 views
0
<!DOCTYPE html> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/ html; charset=utf-8" /> 
<title>Contact Example</title> 

<script type="text/javascript" charset="utf-8" src="phonegap.js"></script> 
<script type="text/javascript" charset="utf-8"> 

document.write("loading PhoneGap"); 
document.addEventListener("deviceready", onDeviceReady, false); 

document.write("PhoneGap loaded"); 
function onDeviceReady() { 
alert("begin"); 
var myContact = navigator.service.contacts.create({"displayName": "Test User"}); 
myContact.gender = "male"; 
document.write("The contact, " + myContact.displayName + ", is of the " + myContact.gender + " gender"); 
alert("end"); 
} 

</script> 
</head> 
<body> 
<h1>Example</h1> 
<p>Create Contact</p> 
</body> 
</ html> 

在Android的Eclipse的仿真结果是:有一些问题 “的console.log”

loadingPhoneGap的PhoneGap加载 例 创建联系人

“警报” 缺失,似乎那个功能不起作用,问题是什么?

回答

0

它应该是:

navigator.contacts.create 

navigator.service.contacts.create 

而且,你有一些JavaScript的排序问题。这是一个完整的工作的index.html:

<!DOCTYPE html> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/ html; charset=utf-8" /> 
<title>Contact Example</title> 

<script type="text/javascript" charset="utf-8" src="phonegap-1.4.1.js"></script> 

<script type="text/javascript" charset="utf-8"> 

var onDeviceReady = function() { 
alert("begin"); 
var myContact = navigator.contacts.create({"displayName": "Test User"}); 
myContact.gender = "male"; 
alert("The contact, " + myContact.displayName + ", is of the " + myContact.gender + " gender"); 
alert("end"); 
}; 

document.write("loading PhoneGap"); 
document.addEventListener("deviceready", onDeviceReady, false); 

document.write("PhoneGap loaded"); 



</script> 
</head> 
<body> 
<h1>Example</h1> 
<p>Create Contact</p> 
</body> 
</html>