|
我在学习phonegap开发的时候遇到了一个问题,在学习到通讯录部分时,发现API无法正常使用。我所用的代码是官方给出的例子
<!DOCTYPE html>
<html>
<head>
<title>Contact Example</title>
<script src="phonegap.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
// 等待加载PhoneGap
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap加载完毕 function onDeviceReady()
{
var myContact = navigator.service.contacts.create({"displayName": "Test User"});
myContact.gender = "male";
console.log("The contact, " + myContact.displayName + ", is of the " + myContact.gender + " gender");
}
</script>
</head>
<body>
<h1>Example</h1>
<p>Create Contact</p>
</body>
</html>
最初我使用的环境是ANDROID 4.4+PhoneGap 2.9.0 在LOGCAT中并没有出现响应的信息,后来将console.log("The contact, " + myContact.displayName + ", is of the " + myContact.gender + " gender"); 这一句换成了alert("xxx");也并没有弹框,于是再看LOGCAT中的信息发现了一句:Unable to open asset URL: file:///android_asset/www/cordova_plugins.js。后来考虑到可能是2.9.0版本不兼容4.4,于是又换了2.2版本的SDK,依然无法正常,运行之后在LOGCAT中没有出现红色的信息,但是依然无法使用通讯录,于是我又尝试了PHONEGAP中国上的另一个例子
<!DOCTYPE html>
<html>
<head>
<title>Contact Example</title>
<script src="phonegap.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
// 等待加载PhoneGap
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap加载完毕
function onDeviceReady() {
// 从全部联系人中进行搜索
var options = new ContactFindOptions();
options.filter="";
var filter = ["displayName","addresses"];
navigator.service.contacts.find(filter, onSuccess, onError, options);
}
// onSuccess: 返回当前联系人结果集的快照
function onSuccess(contacts) {
// 显示所有联系人的地址信息
for (var i=0; i<contacts.length; i++) {
for (var j=0; j<contacts.addresses.length; j++) {
alert("Pref: " + contacts.addresses[j].pref + "\n" +
"Type: " + contacts.addresses[j].type + "\n" +
"Formatted: " + contacts.addresses[j].formatted + "\n" +
"Street Address: " + contacts.addresses[j].streetAddress + "\n" +
"Locality: " + contacts.addresses[j].locality + "\n" +
"Region: " + contacts.addresses[j].region + "\n" +
"Postal Code: " + contacts.addresses[j].postalCode + "\n" +
"Country: " + contacts.addresses[j].country);
}
}
}
// onError: 获取联系人结果集失败
function onError() {
alert('onError!');
}
</script>
</head>
<body>
<h1>Example</h1>
<p>Find Contact</p>
</body>
</html>
之后依然没有什么效果,求管理大哥帮我一下
|
|