我目前正在开展一个从三星 Galaxy Watch 检索心率原始数据的项目。我已按照网站上的代码进行操作,但出现错误。这是我的代码:
window.onload = function () { // TODO:: 做你的初始化工作
tizen.ppm.requestPermission("http://tizen.org/privilege/healthinfo", onsuccessCB,onerrorCB );
var HRMrawsensor = tizen.sensorservice.getDefaultSensor("HRM_RAW");
function onGetSuccessCB(sensorData)
{
console.log("HRMRaw light intensity: " + sensorData.lightIntensity);
}
function onerrorCB(error)
{
console.log("Error occurred");
}
function onsuccessCB()
{
console.log("HRMRaw sensor start");
HRMrawsensor.getHRMRawSensorData(onGetSuccessCB, onerrorCB);
}
HRMrawsensor.start(onsuccessCB);
// add eventListener for tizenhwkey
document.addEventListener('tizenhwkey', function(e) {
if(e.keyName == "back")
try {
tizen.application.getCurrentApplication().exit();
} catch (ignore) {
}
});
// Sample code
var textbox = document.querySelector('.contents');
textbox.addEventListener("click", function(){
box = document.querySelector('#textbox');
box.innerHTML = box.innerHTML == "Basic" ? "Sample" : "Basic";
});
};
我在控制台上得到的内容如下: file:///js/main.js (20) :HRMRaw sensor start ########## exception TypeError: Cannot read property 'getHRMRawSensorData' of undefined
有人知道为什么会这样吗?谢谢