简体   繁体   English

在三星Gear S3前沿上访问心率监测器的“权限被拒绝” Tizen Web应用程序错误

[英]“Permission denied” Tizen web app error accessing the heart rate monitor on a Samsung Gear S3 frontier

I'm trying to create a web app in tizen for my Samsung Gear S3 frontier. 我正试图为我的Samsung Gear S3前沿创建一个网络应用程序。 But, I'm getting a "Permission denied" security error. 但是,我收到“权限被拒绝”安全错误。

I have: 我有:

<tizen:privilege name="http://developer.samsung.com/privilege/healthinfo"/>

and

<tizen:privilege name="http://tizen.org/privilege/healthinfo"/>

enabled in my config.xml. 在我的config.xml中启用。

I can get heart rate readings if I enable sensors permissions for the app in the settings, but it resets every time I compile and upload a newer version, which is rather tedious. 如果我在设置中启用了该应用程序的传感器权限,则可以获取心率读数,但是每次我编译并上传新版本时,它都会重置,这很繁琐。

This is my JS code, sort-of following Retrieving Data from GEAR S3 Heart Rate Monitor (HRM) to Mobile or Server : 这是我的JS代码,在将数据从GEAR S3心率监视器(HRM)检索到移动设备或服务器之后

window.onload = function () {
    // 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');
    var box = document.querySelector('#textbox');

    textbox.addEventListener("click", function(){
        console.log('have box');

        if (fetch === undefined) {
            box.innerHTML = 'No such thing as fetch';
        } else {
            box.innerHTML = "We have fetch";            
        }
    });

    var sensors = tizen.sensorservice.getAvailableSensors();
    console.log('Available sensors: ' + sensors.toString());

    var heartRateData=0;

    function onsuccessCB(hrmInfo) {

        box.innerHTML = 'Heart rate: ' + hrmInfo.heartRate;
        heartRateData = hrmInfo.heartRate;
        // holding 15 seconds as HRM sensor needs some time 
    }

    function onerrorCB(error) {
        tizen.humanactivitymonitor.stop('HRM');
        console.log('Error occurred: ' + error.message);
    }

    function onchangedCB(hrmInfo) {
        //alert("onChanged...");
        tizen.humanactivitymonitor.getHumanActivityData('HRM', onsuccessCB, onerrorCB);

    }

    tizen.humanactivitymonitor.start('HRM', onchangedCB);
};

I would expect the config.xml settings to take care of the permissions, but evidently it doesn't. 我希望config.xml设置能够处理权限,但显然不会。 The watch is running Tizen 4.0.0.2 and it is sporting a "HRM_RAW" sensor, which I am unable to access as well without manually setting the permission. 该手表运行的是Tizen 4.0.0.2,并且运行的是“ HRM_RAW”传感器,如果不手动设置权限,我也无法访问该传感器。

How do I solve this problem? 我该如何解决这个问题?

I think I've found the answer myself, after some more creative web searching. 经过一些更具创意的网络搜索,我想自己找到了答案。 It is done using tizen.ppm.requestPermission() (following https://developer.tizen.org/forums/web-application-development/security-exception-while-accessing-hrm 它是使用tizen.ppm.requestPermission() (遵循https://developer.tizen.org/forums/web-application-development/security-exception-while-accessing-hrm

This results in the expected behaviour. 这导致了预期的行为。 The app asks at installation through the wearable user interface whether the permission should be granted, and if this decision should be the default. 该应用程序在安装时通过可穿戴用户界面询问是否应授予该权限,以及该决定是否为默认设置。

However, I did some refactoring as you often need several permissions in your app, and callback hell is waiting just around the corner. 但是,我做了一些重构,因为您的应用程序中经常需要多个权限,并且回调地狱就在附近。 So I wrote a Promise wrapper around the tizen call: 所以我围绕着tizen调用写了一个Promise包装器:

function requestPermit(uri) {
  return new Promise(function(resolve, reject) {
    tizen.ppm.requestPermission(uri,
      function(success) => { resolve(success); },
      function(error) => { reject(error); });
  });
}

which allows me to 这使我能够

function main() {
  return permitRequester('http://tizen.org/privilege/healthinfo')
    .then(function() { return permitRequester('http://developer.samsung.com/privilege/healthinfo'); })
    .then(function() { return permitRequester('http://developer.samsung.com/privilege/medicalinfo'); })
    .then(function() { return displayHeartRate(); })
    .catch(function(err) { return console.log(err); });
}

window.onload = main();

Hope this is of help to anyone. 希望这对任何人都有帮助。 I created a ES2016 npm/webpack project out of it if you need more info, at https://github.com/reinvantveer/Axyll 如果您需要更多信息,请通过https://github.com/reinvantveer/Axyll从中创建一个ES2016 npm / webpack项目。

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

相关问题 是否可以通过蓝牙将传感器数据从Samsung Gear S3手表(例如心率数据)发送到智能手表应用程序(反应本机或离子应用程序)? - Is there a way to send sensor data from a Samsung Gear S3 watch(e.g. heart rate data) to a smartwatch app(react native or Ionic app) via bluetooth? Tizen Gear 2 Web请求 - Tizen gear 2 web request Tizen Gear Web应用程序,使用文本数据启动Web应用程序 - Tizen gear web app, launch web app with text data 心率监测器 - Heart Rate Monitor 创建一个心率监测器 - Creating a heart rate monitor Tizen Web应用程序可以在模拟器上运行,但不能在Gear 3上运行 - Tizen web app works on simulator, but doesn't work on gear 3 我正在尝试在文本文件中为Samsung Gear S的Tizen可穿戴式应用程序写入一些数据 - I'm trying to write on a text file some data in a Tizen wearable application for Samsung Gear S 如何使用三星 Tizen Gear s2 中的边框滚动列表中的项目? - How to scroll through items in a list using bezel in Samsung Tizen Gear s2? console.log无法在Samsung Tizen TV Emulator(网络应用程序)中运行 - console.log not work in Samsung Tizen TV Emulator (web app) Tizen Gear 2与Android Native Java App的通信 - Tizen Gear 2 to Android Native Java App Communication
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM