我試圖在Android設備(Samsung Galaxy S II)上首次運行PhoneGap;但是,它似乎並不奏效。PhoneGap未在Android中運行
下面的代碼我試圖至今:
<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>
沒有顯示窗口!沒有警報,沒有日誌,它只顯示一個含有body
以上內容的HTML頁面。
@編輯:它現在顯示結果;但是,所有結果都是null
,顯示在Alert
對話框中。 有沒有人遇到過這個?
你的'contacts.length'是什麼? –
@PratikSharma:找到的聯繫人數量。我的手機結果是'693',但所有'displayName'都是'null'。它不應該根據這個'null':http://docs.phonegap.com/en/2.2.0/cordova_contacts_contacts.md.html#Contact –
你可以嘗試把它放在alert'contacts [i] .name .givenName'並看到它仍然爲空? –