我正在開發我的第一個應用程序在phonegap(android)。PhoneGap - OnDeviceReady方法沒有被調用
的index.html
<!DOCTYPE html>
<html>
<head>
<title>Device Properties Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-1.7.0.js"></script>
<script type="text/javascript" charset="utf-8">
alert('code: 1');
// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);
alert('code: 2');
var watchID = null;
alert('code: 3');
// Cordova is ready
//
function onDeviceReady() {
// Update every 3 seconds
alert('code: 4');
var options = { frequency: 3000 };
watchID = navigator.geolocation.watchPosition(onSuccess, onError, options);
}
// onSuccess Geolocation
//
function onSuccess(position) {
alert('code: 5');
var element = document.getElementById('geolocation');
element.innerHTML = 'Latitude: ' + position.coords.latitude + '<br />' +
'Longitude: ' + position.coords.longitude + '<br />' +
'<hr />' + element.innerHTML;
}
// clear the watch that was started earlier
//
function clearWatch() {
alert('code: 6');
if (watchID != null) {
navigator.geolocation.clearWatch(watchID);
watchID = null;
}
}
// onError Callback receives a PositionError object
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
</script>
</head>
<body>
<p id="geolocation">Watching geolocation...</p>
<button onclick="clearWatch();">Clear Watch</button>
</body>
</html>
這裏onDeviceReady方法不獲取調用。請幫助我瞭解我錯過了什麼。
我已經添加了這些權限
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
在manifest.xml文件。
我越來越警覺('代碼:3'),但ondevicereadymethod沒有被調用。我不知道我錯過了什麼。請幫助我一樣。 – Prem
你有沒有嘗試過的例子android應用程序自帶cordova 1.7? – dhaval
嗨user623517,我試過你的例子,它工作得很好。你爲什麼不嘗試在另一臺設備上,然後更新我們自己的產品 – Neji