如何在科尔多瓦中使用网络连接插件



我正在使用Apache Cordova开发一个Android应用程序。在初始屏幕之后,如果找不到互联网连接,我想显示一条消息。我已经安装了cordova插件网络信息插件,但我不知道如何使用它。我已经阅读了文档,但没有得到任何内容。

这是我的索引.html文件:

<!DOCTYPE html>
<html>
<head>
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<link rel="stylesheet" type="text/css" href="css/index.css">
<title>Findajob</title>
<style>
body, html {
width: 100%;
height: 100%;
overflow: hidden;
}
iframe {
width: 100%;
height: 100%;
border: none;
}
</style>
</head>
<body>
<iframe height="100%" src="http://www.mywebsite.com/"></iframe>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</body>
</html>

这是我的索引.js文件:

var app = {
initialize: function() {
document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
},
onDeviceReady: function() {
this.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
}
};
app.initialize();

这是我的配置.xml文件:

<?xml version='1.0' encoding='utf-8'?>
<widget id="io.cordova.com" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>FindaJob</name>
<description>
Find jobs in UK.
</description>
<author email="myemail@gmail.com" href="http://www.findajob.af/">
Fareed Shuja
</author>
<preference name="SplashScreen" value="screen" />
<preference name="SplashScreenDelay" value="3000" />
<preference name="SplashMaintainAspectRatio" value="true" />
<content src="index.html" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="android">
<splash density="land-hdpi" src="res/screen/android/screen1l.png" />
<splash density="land-ldpi" src="res/screen/android/screen2l.png" />
<splash density="land-mdpi" src="res/screen/android/screen3l.png" />
<splash density="land-xhdpi" src="res/screen/android/mainscreen.png" />
<splash density="port-hdpi" src="res/screen/android/screen1p.png" />
<splash density="port-ldpi" src="res/screen/android/screen2p.png" />
<splash density="port-mdpi" src="res/screen/android/screen3p.png" />
<splash density="port-xhdpi" src="res/screen/android/mainscreen.png" />
</platform>
<platform name="android">
<icon density="ldpi" src="res/icon/android/icon-36-ldpi.png" />
<icon density="mdpi" src="res/icon/android/icon-48-mdpi.png" />
<icon density="hdpi" src="res/icon/android/icon-72-hdpi.png" />
<icon density="xhdpi" src="res/icon/android/icon-96-xhdpi.png" />
<icon density="xxhdpi" src="res/icon/android/icon-144-xxhdpi.png" />
<icon density="xxxhdpi" src="res/icon/android/icon-192-xxxhdpi.png" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
<engine name="android" spec="^6.2.3" />
<engine name="browser" spec="^4.1.0" />
<plugin name="cordova-plugin-network-information" spec="^1.3.3" />
<plugin name="cordova-plugin-splashscreen" spec="^4.0.3" />
<plugin name="cordova-plugin-whitelist" spec="^1.3.2" />
</widget>

请帮忙。我只想显示

找不到互联网连接

消息(如果未连接到互联网(。

你这个插件

https://github.com/apache/cordova-plugin-network-information

这将提供有关设备的蜂窝和wifi的信息 连接。

最新更新