【发布时间】:2012-07-30 20:40:30
【问题描述】:
我需要使用 phonegap 从 android 设备获取联系人列表.....我已经关注了这个
并写了这段代码
<!DOCTYPE html>
PhoneGap 设备就绪示例
<script type="text/javascript" charset="utf-8" src="phonegap-1.4.1.js"></script>
<script type="text/javascript" charset="utf-8">
// Call onDeviceReady when PhoneGap is loaded.
//
// At this point, the document has loaded but phonegap-1.0.0.js has not.
// When PhoneGap is loaded and talking with the native device,
// it will call the event 'deviceready'.
//
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is loaded and it is now safe to make calls PhoneGap methods
//
function onDeviceReady() {
var options = new ContactFindOptions();
options.filter="Bob";
var fields = ["displayName", "name"];
navigator.contacts.find(fields, onSuccess, onError, options);
}
function onSuccess(contacts) {
alert('OnSucess!');
for (var i=0; i<contacts.length; i++) {
console.log("Display Name = " + contacts[i].displayName);
}
}
// onError: Failed to get the contacts
//
function onError(contactError) {
alert('onError!');
}
</script>
我已在我的清单中授予此权限
- android.permission.GET_ACCOUNTS
- android.permission.READ_CONTACTS
- android.permission.WRITE_CONTACTS
&这个插件
<plugin name="Contacts" value="com.phonegap.ContactManager"/>
我使用的是 phonegap 版本 1.4.1,当我运行我的应用程序时,我总是收到警报('OnError'); 背后的原因应该是什么?是版本控制问题吗?任何指南表示赞赏 谢谢
【问题讨论】:
-
你最好检查一下
contactError,alert('onError!')没有意义。并引发任何错误/异常?看看你的 LogCat 输出。
标签: android cordova phonegap-plugins