我用这些命令为android制作了一个新的Cordova App:
$ cordova create hello com.example.hello HelloWorld
$ cordova platform add android
,它成功了。然后我添加了Dropboc同步插件
cordova plugin add https://github.com/rossmartin/phonegap-dropbox-sync-android.git
,但我不能访问JS变量。I tried
try{
DropboxSync.checkLink(function() { // success
alert("ok");
// User is already authenticated with Dropbox.
}, function() { // fail
alert("fail");
// User is not authenticated with Dropbox.
});
DropboxSync.link();
}catch(e){alert(e);}
和alert或者alert中的e表示:
ReferenceError: DropboxSync is not defined
我忘了什么吗?
改变index . 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>
尝试使用窗口。DropboxSync,也不要忘记检查是否正确安装了android。(如果你使用netbeans,你可以在plugins文件夹下的Files窗口中看到它)