【发布时间】:2023-03-04 20:50:01
【问题描述】:
我第一次尝试在 Android 设备(三星 Galaxy S II)上运行 PhoneGap;但是,它似乎不起作用。
这是我目前尝试的代码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi"
/>
<title>Hello World</title>
<script type="text/javascript" src="cordova-2.2.0.js"></script>
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
var options = new ContactFindOptions();
options.filter = "";
options.multiple = true;
var filter = ["displayName"];
navigator.contacts.find(filter, onSuccess, onError, options);
}
function onSuccess(contacts) {
for(var i = 0; i < contacts.length; ++i) {
alert(contacts[i].displayName);
}
alert("OK then");
console.log("OK");
}
function onError(contactError) {
alert("onError!");
console.log("Fail");
}
</script>
</head>
<body >
</body>
<h1> Example </h1>
<p> Find Contacts </p>
</html>
没有出现!没有警报,没有日志,它只是显示一个 HTML 页面,上面有 body 内容。
@Edit:现在显示结果;但是,所有结果都是null,显示在Alert 对话框中。
有人经历过吗?
【问题讨论】:
-
你的
contacts.length是什么? -
@PratikSharma:找到的联系人数量。我的电话结果是
693,但所有displayName都是null。根据这个不应该是null:docs.phonegap.com/en/2.2.0/… -
您可以尝试将其放入警报
contacts[i].name.givenName并查看它仍然为空吗? -
@PratikSharma:好的,更新
var filter = ["displayName", "name"];和alert(contacts[i].displayName);仍然会导致null。 -
我已经为您的问题发布了可行的解决方案。尝试一下,让我知道它是否对您有帮助。谢谢。