我需要使用 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');背后的原因应该是什么?是版本控制问题吗?感谢任何指南谢谢