Tôi đang cố gắng chạy PhoneGap lần đầu tiên trên thiết bị Android (Samsung Galaxy S II); tuy nhiên, nó dường như không hoạt động.PhoneGap không chạy trong Android
Dưới đây là đoạn code tôi cố gắng cho đến nay:
<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>
Không có gì show-up! Không cảnh báo, không có nhật ký, nó chỉ hiển thị một trang HTML với nội dung trên body
.
@Edit: nó hiển thị kết quả ngay bây giờ; tuy nhiên, tất cả kết quả là null
, hiển thị trên hộp thoại Alert
. Có ai có kinh nghiệm này không?
'contacts.length' của bạn là gì? –
@PratikSharma: số liên lạc được tìm thấy. Điện thoại của tôi có kết quả là '693', nhưng tất cả 'displayName' là' null'. Nó không nên là 'null' theo điều này: http://docs.phonegap.com/en/2.2.0/cordova_contacts_contacts.md.html#Contact –
bạn có thể thử đặt câu lệnh này trong các liên hệ cảnh báo [i] .name .givenName' và thấy nó vẫn là null? –