本文介绍了PhoneGap的 - OnDeviceReady方法没有得到所谓的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发中的PhoneGap(机器人)我的第一个应用程序。
I am developing my first application in phonegap (android).
<!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方法是没有得到调用。请帮助我了解我错过了什么。
Here onDeviceReady method is not getting called. Kindly help me understand what i am missing.
我已经添加了这些权限
<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文件。
in manifest.xml file.
推荐答案
按照这种方式,它应该工作。
Follow it this way and it should be working.
<!DOCTYPE html>
<html>
<head>
<title>Cordova Device Ready Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-1.7.0.js"></script>
<script type="text/javascript" charset="utf-8">
// Call onDeviceReady when Cordova is loaded.
//
// At this point, the document has loaded but cordova-1.7.0.js has not.
// When Cordova is loaded and talking with the native device,
// it will call the event `deviceready`.
//
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
// Cordova is loaded and it is now safe to make calls Cordova methods
//
function onDeviceReady() {
// Now safe to use the Cordova API
}
</script>
</head>
<body onload="onLoad()">
</body>
</html>
另外,还要检查的Android例如文件夹在科尔多瓦1.7下载。
Also check the Android example folder in the Cordova 1.7 download.
这篇关于PhoneGap的 - OnDeviceReady方法没有得到所谓的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!