使用html检查可穿戴的网络可用性

时间:2016-08-04 12:57:25

标签: tizen tizen-web-app

使用HTML和javascript,有没有办法检查三星gear s2中的网络是否可用?

1 个答案:

答案 0 :(得分:1)

如果您想查看互联网连接状态,请尝试使用

<强>的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();
            }
        }
    } );
} () );
  

不要忘记在配置文件中添加这些内容。   的 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>
  

我只是检查一下。这对我来说可以。您还可以查看this

如果您只想查看wifi状态,

wifiData.signalStrength // provide the signal strength
wifiData.status // return ON or OFF to get the wifi status

检查this