javascript - 如何启动我的线上和线下事件

标签 javascript html events plugins cordova

我正在使用 cordova 3.4。 (安卓)

我设置了 4 个要触发的事件:

  • 设备就绪
  • 恢复
  • 在线
  • 离线

问题是线上和线下事件根本没有触发。

根据文档,我在deviceready之前设置了onResume监听器,在其之后设置了online/offline。

这就是我所做的。

事件脚本:

function onLoad() {
document.addEventListener("online", onGoesOnLine, false);
document.addEventListener("offline", onGoesOffLine, false);
document.addEventListener("deviceready", onDeviceReady, false);
}

function onDeviceReady() {
document.addEventListener("resume", onResumeApp, false);
var db = window.openDatabase("Database", "1.0", "MondialRelay", 200000);
db.transaction(creerBaseDonneesSiNonExist, function(err){
console.log("erf ...");
 }, function(){
  console.log("hell yeah");
 });
}

function onGoesOnLine(){
 alert("onLine");
}

function onGoesOffLine(){
 alert("offLine");
}

function onResumeApp(){
 alert("onResume");
 window.location = "offLineIndex.html";
}

配置.xml:

<?xml version='1.0' encoding='utf-8'?>
<widget id="fr.mondialrelay.appli" 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" />
<feature name="App">
    <param name="android-package" value="org.apache.cordova.App" />
</feature>
<name>MondialRelay</name>
<description>
</description>
<author email="dev@cordova.apache.org" href="http://cordova.io">
</author>
<content src="index.html" />
<access origin="*" />
<feature name="NetworkStatus">
    <param name="android-package" value="org.apache.cordova.networkinformation.NetworkManager" />
</feature>
<feature name="Device">
    <param name="android-package" value="org.apache.cordova.device.Device" />
</feature>
<feature name="Geolocation">
    <param name="android-package" value="org.apache.cordova.geolocation.GeoBroker" />
</feature>
<feature name="Battery">
    <param name="android-package" value="org.apache.cordova.batterystatus.BatteryListener" />
</feature>
<plugin name="Storage" value="org.apache.cordova.Storage" />
<plugin name="Geolocation" value="org.apache.cordova.GeoBroker" />
<plugin name="NetworkStatus" value="org.apache.cordova.NetworkManager" />
</widget>

AndroidManifest.xml:

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" android:windowSoftInputMode="adjustPan" package="fr.mondialrelay.appli" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:name="MondialRelay" android:theme="@android:style/Theme.Black.NoTitleBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
</manifest>

这是我运行“cordova plugin ls”命令时看到的内容:

[ 'org.apache.cordova.battery-status',
'org.apache.cordova.device',
'org.apache.cordova.geolocation',
'org.apache.cordova.network-information' ]

我不认为我错过了任何东西,但它仍然不起作用......

我知道这个问题已经被问过很多次了,但即使在阅读了答案之后,我也不知道如何让它发挥作用。

首先,当我测试时,我将应用程序置于暂停状态以切断我的互联网连接,我认为这可能是问题所在..然后我用手机设置了一个wifi,然后在应用程序运行时,我只是将其关闭..无法收到任何警报..

谢谢你的帮助;) 问候。

最佳答案

没有任何效果... 我确实找到了解决该问题的方法...

  • 将 WWW 文件夹保存在某处。
  • 转到项目的根目录。
  • 添加您需要的所有插件(如果尚未完成)
  • Cordova Build 在项目根目录下的 cordova CLI 中

然后复制/粘贴您之前保存的www文件夹的内容,而不是cordova CLI创建的新文件夹(不要替换cordova.js、cordova_plugin.js和plugins文件夹)

然后转到你的 Eclipse IDE,编译,它应该可以工作:)

希望有帮助。 问候。

关于javascript - 如何启动我的线上和线下事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22452864/

相关文章:

java - 其他复合小部件未接收 ChangeEvent

java - SWT:在 Linux 上使用 setEnabled() 后单击按钮出现问题

c# - wpf 附加属性 : where to unsubscribe from event handling?

javascript - Chrome 开发者工具中的数据不一致

javascript - phaser.io 多个 phaser.game 实例

javascript - Typeahead.js - 建议不是函数

javascript - Vue 不将事件传递给 child

javascript - 如果选中里面的复选框,则更改 div 背景颜色

javascript - 如何通过搜索该元素的另一个属性来找到该元素的属性

html - 如何在不使用边距或填充的情况下将带有按钮中心的 div 与左侧的 Logo 对齐