繁体   English   中英

Tizen Web应用程序可以在模拟器上运行,但不能在Gear 3上运行

[英]Tizen web app works on simulator, but doesn't work on gear 3

我正在尝试开发一个从加速度传感器读取数据并将其保存在文本文件中的应用程序。 通过使用Web应用程序开发,我设法使该应用程序可以在模拟器上运行,但是当我在Samsung Gear 3前沿上对其进行尝试时,它无法正常工作。 可以找出我做错了什么吗? 以下是html和Java脚本代码。

 <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width,user-scalable=no"> <title>Basic</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> <h2 class="ui-title">TAU Basic</h2> </header> <div class="ui-content ui-content-padding"> <p id="readings"> Basic </p> </div> </div> <script src="lib/tau/wearable/js/tau.min.js"></script> <script src="js/app.js"></script> <script src="js/lowBatteryCheck.js"></script> <script src="js/circle-helper.js"></script> </body> </html> 

Java脚本代码:

 function init() { console.log("app started"); document.getElementById("readings").innerHTML="Starting"; accelerationSensor=tizen.sensorservice.getDefaultSensor("ACCELERATION"); if (accelerationSensor){ console.log("Sensor captured"); } /* Update the clock hands every second */ accelerationSensor.start(onsuccessCB); setInterval(function() { updateTime(); }, 1000); } window.onload = init(); function onGetSuccessCB(sensorData) { var datetime = tizen.time.getCurrentDateTime(); var Date = ("0" + datetime.getHours()).slice(-2) + ":" + ("0" + datetime.getMinutes()).slice(-2) + ":" + ("0" + datetime.getSeconds()).slice(-2); console.log(Date); console.log("######## Get acceleration sensor data ########"); console.log("x: " + sensorData.x); console.log("y: " + sensorData.y); console.log("z: " + sensorData.z); x = sensorData.x; y = sensorData.y; z = sensorData.z; tizen.filesystem.resolve("documents", function(dir) { var newFile = dir.resolve("newFilePath.txt");; newFile.openStream( "a", function(fs) { fs.write(Date+"\\tx:"+x+"\\ty:"+y+"\\tz:"+z+"\\n"); fs.close(); }, function(e) { console.log("Error " + e.message); }, "UTF-8"); },function(){ document.getElementById("readings").innerHTML="Error"; }); document.getElementById("readings").innerHTML="Reading"; } function onerrorCB(error) { console.log("error occurred: " + error.message); } function onsuccessCB() { console.log("acceleration sensor start"); var datetime = tizen.time.getCurrentDateTime(); var hour = datetime.getHours(), var minute = datetime.getMinutes(), var second = datetime.getSeconds(); tizen.filesystem.resolve("documents", function(dir) { newFile = dir.createFile("newFilePath.txt"); newFile.openStream( "w", function(fs) { fs.write(hour+":"+minute+":"+second+"\\tstart of recording \\n"); fs.close(); }, function(e) { console.log("Error " + e.message); }, "UTF-8"); },function(){ document.getElementById("readings").innerHTML="Error"; }); } function updateTime() { accelerationSensor.getAccelerationSensorData(onGetSuccessCB, onerrorCB); } (function () { window.addEventListener("tizenhwkey", function (ev) { var activePopup = null, page = null, pageid = ""; if (ev.keyName === "back") { activePopup = document.querySelector(".ui-popup-active"); page = document.getElementsByClassName("ui-page-active")[0]; pageid = page ? page.id : ""; if (pageid === "main" && !activePopup) { try { tizen.application.getCurrentApplication().exit(); } catch (ignore) { } } else { window.history.back(); } } }); }()); 

提前致谢。

我设法找到了解决方案,并将其发布为帮助其他将面临相同问题的人。

事实证明,S3中没有加速度传感器,并且当我将加速度传感器从Acceleration更改为linear_acceleration时,一切正常。 html和javascript的代码如下:

 <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width,user-scalable=no"> <title>Basic</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> <h2 class="ui-title">TAU Basic</h2> </header> <div class="ui-content ui-content-padding"> <p id="readings"> Basic </p> </div> </div> <script src="lib/tau/wearable/js/tau.min.js"></script> <script src="js/app.js"></script> <script src="js/lowBatteryCheck.js"></script> <script src="js/circle-helper.js"></script> </body> </html> 

JavaScript:

 var accelerationSensor; function onsuccessCB() { console.log("acceleration sensor start"); var datetime = tizen.time.getCurrentDateTime(); var hour = datetime.getHours(); var minute = datetime.getMinutes(); var second = datetime.getSeconds(); tizen.filesystem.resolve("documents", function(dir) { var newFile = dir.createFile("newFilePath.txt"); newFile.openStream( "w", function(fs) { fs.write(hour + ":" + minute + ":" + second + "\\tstart of recording \\n"); fs.close(); document.getElementById("readings").innerHTML = "Reading"; }, function(e) { document.getElementById("readings").innerHTML = "File Error"; }, "UTF-8"); }); } function init() { console.log("app started"); document.getElementById("readings").innerHTML = "Starting"; accelerationSensor = tizen.sensorservice.getDefaultSensor("LINEAR_ACCELERATION"); document.getElementById("readings").innerHTML = "Starting1"; if (accelerationSensor) { console.log("Sensor captured"); document.getElementById("readings").innerHTML = "Acceleration"; } else { document.getElementById("readings").innerHTML = "Error"; } /* Update the clock hands every second */ accelerationSensor.start(onsuccessCB); document.getElementById("readings").innerHTML = "onsuccessCB done"; console.log("onsuccessCB done"); setInterval(function() { updateTime(); }, 1000); } window.onload = init(); function onGetSuccessCB(sensorData) { var datetime = tizen.time.getCurrentDateTime(); var Date = ("0" + datetime.getHours()).slice(-2) + ":" + ("0" + datetime.getMinutes()).slice(-2) + ":" + ("0" + datetime.getSeconds()).slice(-2); console.log(Date); console.log("######## Get acceleration sensor data ########"); console.log("x: " + sensorData.x); console.log("y: " + sensorData.y); console.log("z: " + sensorData.z); var x = sensorData.x; var y = sensorData.y; var z = sensorData.z; tizen.filesystem.resolve("documents", function(dir) { var newFile = dir.resolve("newFilePath.txt"); newFile.openStream( "a", function(fs) { fs.write(Date + "\\tx:" + x + "\\ty:" + y + "\\tz:" + z + "\\n"); fs.close(); }, function(e) { console.log("Error " + e.message); }, "UTF-8"); }, function() { document.getElementById("readings").innerHTML = "Error"; }); document.getElementById("readings").innerHTML = "Reading"; } function onerrorCB(error) { console.log("error occurred: " + error.message); } function updateTime() { accelerationSensor.getLinearAccelerationSensorData(onGetSuccessCB); } (function() { window.addEventListener("tizenhwkey", function(ev) { var activePopup = null, page = null, pageid = ""; if (ev.keyName === "back") { activePopup = document.querySelector(".ui-popup-active"); page = document.getElementsByClassName("ui-page-active")[0]; pageid = page ? page.id : ""; if (pageid === "main" && !activePopup) { try { tizen.application.getCurrentApplication().exit(); } catch (ignore) {} } else { window.history.back(); } } }); }()); 

上面的代码将获取linear_acceleration传感器的读数,并将其保存到“文档”文件夹中的文本文件中。 您需要具有filesystem.read和filesystem.write特权才能访问“文档”文件夹。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM