Веб-приложение Tizen работает на симуляторе, но не работает на передаче 3 - PullRequest
0 голосов
/ 26 мая 2018

Я пытаюсь разработать приложение, которое считывает данные с датчика ускорения и сохраняет их в текстовом файле.Используя разработку веб-приложений, мне удалось заставить приложение работать на эмуляторе, но когда я попробовал его на границе 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+"\t x:"+x+"\t y:"+y+"\t z:"+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();
			}
		}
	});
}());

Заранее спасибо.

1 Ответ

0 голосов
/ 06 июня 2018

Мне удалось найти решение, и я выкладываю его для помощи другим, кто столкнется с такой же проблемой.

Оказывается, что в S3 нет датчика ускорения, и все работает нормально, когда яизмените датчик с ускорения на линейное ускорение.Коды для 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 + "\t x:" + x + "\t y:" + y + "\t z:" + 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 и сохранит их в текстовый файл в папке «Documents».Чтобы иметь доступ к папке «Документ», вам необходимы привилегии filesystem.read и filesystem.write.

...