我目前正在学习这个并尝试在我的应用中使用多个核心插件,我已经手动编码然后将其提交到phonegap进行构建和测试。现在我已经在Windows 7上安装了cordova,遵循adobe文档中的说明。
在应用程序中创建多个核心插件然后为我构建的phonegap不起作用。我使用过的唯一代码是adobe在3.5版本上的phonegaps文档。如果你使用一个核心插件,它可以工作。您对此问题所需的所有代码都在其文档中。
代码:index.html
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/themes/default/jquery.mobile-1.4.3.min.css" />
<link rel="stylesheet" href="css/animate.min.css" />
<script src="js/jquery.js"></script>
<script src="js/jquery.mobile-1.4.3.min.js"></script>
<script src="cordova.js"></script>
<script>
</script>
</head>
<body>
<!--/////////////////////////////Home - API \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\-->
<div data-role="page" id="home">
<div data-role="header">
<h1>API</h1>
</div><!-- /header -->
<div role="main" class="ui-content">
<ul data-role="listview">
<li><a href="#accel" onclick="readyAccel();">Accelerometer</a></li>
<li><a href="#gps" onclick="readyGPS();">GPS</a></li>
<li><a href="#compass" onclick="readyCompass();">Compass</a></li>
</ul>
</div><!-- /content -->
<div data-role="footer" data-position="fixed">
<h4>Joshua</h4>
</div><!-- /footer -->
</div><!-- /page -->
<!--/////////////////////////////Home - API - END \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\-->
<!--/////////////////////////////Accel - API \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\-->
<div data-role="page" id="accel">
<div data-role="header">
<h1>Accelerometer</h1>
</div><!-- /header -->
<script>
// The watch id references the current `watchAcceleration`
var AccelID = null;
// Wait for device API libraries to load
//
function readyAccel() {
document.addEventListener("deviceready", onDeviceReadyAccel, false);
}
// device APIs are available
//
function onDeviceReadyAccel() {
startAccel();
}
// Start watching the acceleration
//
function startAccel() {
// Update acceleration every .1 seconds
var options = { frequency: 100 };
AccelID = navigator.accelerometer.watchAcceleration(onSuccess, onError, options);
}
// Stop watching the acceleration
//
function stopAccel() {
if (AccelID) {
navigator.accelerometer.clearWatch(AccelID);
AccelID = null;
}
}
// onSuccess: Get a snapshot of the current acceleration
//
function onSuccess(acceleration) {
var element = document.getElementById('accelerometer');
element.innerHTML = 'Acceleration X: ' + acceleration.x + '<br />' +
'Acceleration Y: ' + acceleration.y + '<br />' +
'Acceleration Z: ' + acceleration.z + '<br />' +
'Timestamp: ' + acceleration.timestamp + '<br />';
}
// onError: Failed to get the acceleration
//
function onError() {
alert('onError!');
}
if(!isset($element)) {
alert('failed');
}
</script>
</head>
<body>
<div id="accelerometer">Waiting for accelerometer...</div>
<button onclick="stopAccel();">Stop Watching</button>
</div>
<!--/////////////////////////////Accel - API - END \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\-->
<!--/////////////////////////////GPS - API \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\-->
<div data-role="page" id="gps">
<div data-role="header">
<h1>GPS</h1>
</div>
<script>
// Wait for device API libraries to load
//
function readyGPS() {
document.addEventListener("deviceready", onDeviceReadyGeo, false);
}
var GeoID = null;
// device APIs are available
//
function onDeviceReadyGeo() {
// Get the most accurate position updates available on the
// device.
var options = { enableHighAccuracy: true };
GeoID = navigator.geolocation.watchPosition(onSuccess, onError, options);
}
// onSuccess Geolocation
//
function onSuccess(position) {
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 clearGeo() {
if (GeoID != null) {
navigator.geolocation.clearWatch(GeoID);
GeoID = null;
}
}
// onError Callback receives a PositionError object
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
////////Default Script Start\\\\\\\\\\
// // Wait for device API libraries to load
// //
// document.addEventListener("deviceready", onDeviceReady, false);
//
// var watchID = null;
//
// // device APIs are available
// //
// function onDeviceReady() {
// // Get the most accurate position updates available on the
// // device.
// var options = { enableHighAccuracy: true };
// watchID = navigator.geolocation.watchPosition(onSuccess, onError, options);
// }
//
// // onSuccess Geolocation
// //
// function onSuccess(position) {
// 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() {
// 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');
// }
//////////Default Script End\\\\\\\\\\\\\\\\\
</script>
</head>
<body>
<!--
<p id="geolocation">Watching geolocation...</p>
<button onclick="clearGeo();">Clear Location</button>
-->
<p id="geolocation">Watching geolocation...</p>
<button onclick="clearWatch();">Clear Watch</button>
</div>
<!--/////////////////////////////GPS - API - END \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\-->
<!--/////////////////////////////COMPASS - API \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\-->
<div data-role="page" id="compass">
<div data-role="header">
<h1>Compass</h1>
</div>
<script>
// The watch id references the current `watchHeading`
var CompassID = null;
// Wait for device API libraries to load
//
function readyCompass() {
document.addEventListener("deviceready", onDeviceReadyCompass, false);
}
// device APIs are available
//
function onDeviceReadyCompass() {
startCompass();
}
// Start watching the compass
//
function startCompass() {
// Update compass every .1 seconds
var options = { frequency: 100 };
CompassID = navigator.compass.watchHeading(onSuccess, onError, options);
}
// Stop watching the compass
//
function stopCompass() {
if (CompassID) {
navigator.compass.clearWatch(CompassID);
CompassID = null;
}
}
// onSuccess: Get the current heading
//
function onSuccess(heading) {
var element = document.getElementById('heading');
element.innerHTML = 'Heading: ' + heading.magneticHeading;
}
// onError: Failed to get the heading
//
function onError(compassError) {
alert('Compass error: ' + compassError.code);
}
</script>
</head>
<body>
<div id="heading">Waiting for heading...</div>
<button onclick="stopCompass();">Stop Compass</button>
</div>
<!--/////////////////////////////COMPASS - API - END \\\\\\\\\\\\\\\\\\\\\\\\\\\\\-->
</body>
</html>
代码:config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="io.cordova.hellocordova" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<preference name="loglevel" value="DEBUG" />
<preference name="AndroidLaunchMode" value="singleTop" />
<feature name="App">
<param name="android-package" value="org.apache.cordova.App" />
</feature>
<feature name="Accelerometer">
<param name="android-package" value="org.apache.cordova.devicemotion.AccelListener" />
</feature>
<feature name="Compass">
<param name="android-package" value="org.apache.cordova.deviceorientation.CompassListener" />
</feature>
<name>App Multi</name>
<description>
"Multi plugins"
</description>
<author email="email@address.com" href="http://google.com">
Joshua
</author>
<content src="index.html" />
<access origin="*" />
</widget>
我已经更改了watchID以查看它是否与其他插件冲突但是这不起作用。
链接到API的API: -
我不能发布两个以上的链接,所以我认为你可以很容易地从phonegaps文档中找到指南针。