Javascript Cordova插件引用错误(Dropbox同步)
我用以下命令为android制作了一个新的Cordova应用程序: $cordova create hello com.example.hello HelloWorld $cordova平台添加android 它成功了。然后我添加了Dropboc同步插件 cordova插件添加 但我无法访问JS变量。 我试过了 警报或e-in警报显示: ReferenceError:未定义DropboxSync 我忘了什么吗 已更改的index.html:Javascript Cordova插件引用错误(Dropbox同步),javascript,android,html,cordova,cordova-plugins,Javascript,Android,Html,Cordova,Cordova Plugins,我用以下命令为android制作了一个新的Cordova应用程序: $cordova create hello com.example.hello HelloWorld $cordova平台添加android 它成功了。然后我添加了Dropboc同步插件 cordova插件添加 但我无法访问JS变量。 我试过了 警报或e-in警报显示: ReferenceError:未定义DropboxSync 我忘了什么吗 已更改的index.html: <!DOCTYPE html> <!
<!DOCTYPE html>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
<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" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<meta name="msapplication-tap-highlight" content="no" />
<title>Hello World</title>
</head>
<body>
<div class="app">
<h1>Apache Cordova</h1>
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
</div>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
</script>
<script>
function dropbox_linked() { }
// Called from the onActivityResult method in the plugin when linking is successful.
function dropbox_onSyncStatusChange(status) { }
// Called by observer in the plugin when there's a change
// to the status of background synchronization (download/upload).
// status is a string variable that will be 'sync' or 'none'.
function dropbox_fileChange() { }
// Called by observer in the plugin when a file is changed.
try{
DropboxSync.checkLink(function() { // success
alert("Hallo ok");
// User is already authenticated with Dropbox.
}, function() { // fail
alert("Hallo fail");
// User is not authenticated with Dropbox.
});
alert("Hallo");
DropboxSync.link();
alert("Hallo2");
}catch(e){alert(e);}
</script>
</body>
</html>
尝试使用window.DropboxSync,也别忘了检查android.json是否正确安装。如果您使用netbeans,您可以在文件窗口的plugins文件夹下看到它
<!DOCTYPE html>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
<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" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<meta name="msapplication-tap-highlight" content="no" />
<title>Hello World</title>
</head>
<body>
<div class="app">
<h1>Apache Cordova</h1>
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
</div>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
</script>
<script>
function dropbox_linked() { }
// Called from the onActivityResult method in the plugin when linking is successful.
function dropbox_onSyncStatusChange(status) { }
// Called by observer in the plugin when there's a change
// to the status of background synchronization (download/upload).
// status is a string variable that will be 'sync' or 'none'.
function dropbox_fileChange() { }
// Called by observer in the plugin when a file is changed.
try{
DropboxSync.checkLink(function() { // success
alert("Hallo ok");
// User is already authenticated with Dropbox.
}, function() { // fail
alert("Hallo fail");
// User is not authenticated with Dropbox.
});
alert("Hallo");
DropboxSync.link();
alert("Hallo2");
}catch(e){alert(e);}
</script>
</body>
</html>