使用 html 检查 tizen wearable 中的网络可用性
Network availability check in tizen wearable with html
使用HTML和javascript,有什么方法可以检查Samsung gear s2网络是否可用?
如果你想检查互联网连接状态,试试这样
index.html
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width,user-scalable=no">
<title>Circular UI</title>
<link rel="stylesheet" href="lib/tau/wearable/theme/default/tau.min.css">
<link rel="stylesheet" media="all and (-tizen-geometric-shape: circle)" href="lib/tau/wearable/theme/default/tau.circle.min.css">
<!-- load theme file for your application -->
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="ui-page ui-page-active" id="main">
<header class="ui-header">
<h2 class="ui-title">Basic</h2>
</header>
<div class="ui-content content-padding">
<ul class="ui-listview">
<p id="connectionStatus">N/A</p>
</ul>
</div>
</div>
<script type="text/javascript" src="lib/tau/wearable/js/tau.min.js"></script>
<script type="text/javascript" src="js/circle-helper.js"></script>
<script src="app.js"></script>
<script src="lowBatteryCheck.js"></script>
</body>
</html>
app.js
( function () {
var isOnline = navigator.onLine;
var con = document.getElementById("connectionStatus");
if(isOnline){
con.innerHTML = "Connection is available";
console.log("Connection is available");
}else{
con.innerHTML = "Connection is not available";
console.log("Connection is not available");
}
window.addEventListener( 'tizenhwkey', function( ev ) {
if( ev.keyName === "back" ) {
var page = document.getElementsByClassName( 'ui-page-active' )[0],
pageid = page ? page.id : "";
if( pageid === "main" ) {
try {
tizen.application.getCurrentApplication().exit();
} catch (ignore) {
}
} else {
window.history.back();
}
}
} );
} () );
Don't forget to add these in config file.
config.xml
<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns:tizen="http://tizen.org/ns/widgets" xmlns="http://www.w3.org/ns/widgets" id="http://yourdomain/ConnectionCheck" version="1.0.0" viewmodes="maximized">
<tizen:application id="6NMriwCsz0.ConnectionCheck" package="6NMriwCsz0" required_version="2.3.1"/>
<content src="index.html"/>
<feature name="http://tizen.org/feature/screen.size.normal"/>
<icon src="icon.png"/>
<name>ConnectionCheck</name>
<tizen:privilege name="http://tizen.org/privilege/application.launch"/>
<tizen:profile name="wearable"/>
<tizen:setting hwkey-event="enable"/>
</widget>
I just check this. It works fine for me. You can also check this.
如果您只想检查 wifi 状态,
wifiData.signalStrength // provide the signal strength
wifiData.status // return ON or OFF to get the wifi status
勾选this
使用HTML和javascript,有什么方法可以检查Samsung gear s2网络是否可用?
如果你想检查互联网连接状态,试试这样
index.html
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width,user-scalable=no">
<title>Circular UI</title>
<link rel="stylesheet" href="lib/tau/wearable/theme/default/tau.min.css">
<link rel="stylesheet" media="all and (-tizen-geometric-shape: circle)" href="lib/tau/wearable/theme/default/tau.circle.min.css">
<!-- load theme file for your application -->
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="ui-page ui-page-active" id="main">
<header class="ui-header">
<h2 class="ui-title">Basic</h2>
</header>
<div class="ui-content content-padding">
<ul class="ui-listview">
<p id="connectionStatus">N/A</p>
</ul>
</div>
</div>
<script type="text/javascript" src="lib/tau/wearable/js/tau.min.js"></script>
<script type="text/javascript" src="js/circle-helper.js"></script>
<script src="app.js"></script>
<script src="lowBatteryCheck.js"></script>
</body>
</html>
app.js
( function () {
var isOnline = navigator.onLine;
var con = document.getElementById("connectionStatus");
if(isOnline){
con.innerHTML = "Connection is available";
console.log("Connection is available");
}else{
con.innerHTML = "Connection is not available";
console.log("Connection is not available");
}
window.addEventListener( 'tizenhwkey', function( ev ) {
if( ev.keyName === "back" ) {
var page = document.getElementsByClassName( 'ui-page-active' )[0],
pageid = page ? page.id : "";
if( pageid === "main" ) {
try {
tizen.application.getCurrentApplication().exit();
} catch (ignore) {
}
} else {
window.history.back();
}
}
} );
} () );
Don't forget to add these in config file. config.xml
<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns:tizen="http://tizen.org/ns/widgets" xmlns="http://www.w3.org/ns/widgets" id="http://yourdomain/ConnectionCheck" version="1.0.0" viewmodes="maximized">
<tizen:application id="6NMriwCsz0.ConnectionCheck" package="6NMriwCsz0" required_version="2.3.1"/>
<content src="index.html"/>
<feature name="http://tizen.org/feature/screen.size.normal"/>
<icon src="icon.png"/>
<name>ConnectionCheck</name>
<tizen:privilege name="http://tizen.org/privilege/application.launch"/>
<tizen:profile name="wearable"/>
<tizen:setting hwkey-event="enable"/>
</widget>
I just check this. It works fine for me. You can also check this.
如果您只想检查 wifi 状态,
wifiData.signalStrength // provide the signal strength
wifiData.status // return ON or OFF to get the wifi status
勾选this