2016-08-04 40 views
0

使用HTML和JavaScript,有沒有什麼辦法來檢查網絡是否可用在三星齒輪S2?網頁可用性檢查tizen耐磨與html

+1

你好,你要檢查互聯網連接? –

+0

是的。我嘗試使用此代碼。但它不適合我。 $(document).on('online',function(event){}。在android原生代碼中,我們可以很容易地檢查這個.Tizen本地代碼也提供了檢查這個的方法。 – Priya

回答

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

如果你想只檢查無線網絡連接狀態,

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

檢查this

+0

謝謝..我會嘗試這 – Priya

+0

歡迎。讓我知道的狀態... –

+0

你試過嗎? –