How to access Galaxy S5 heart rate sensor?

最后都变了- 提交于 2019-12-03 21:18:05

You cannot get raw heart rate monitor data from Samsung Galaxy S5.

Sensors Extension SDK is required to get raw data from sensors not supported by Google Android and this page states that:

Sensor Extension SDK has the following restrictions:

  • HRM Sensor IR/RED Signal
    • Devices with Android 5.0 (Lollipop API level 21) or higher is required.
    • Galaxy S5 and Galaxy S5mini are excluded.
    • Only supported by Samsung device with HRM sensor.

Use SensorManager.getDefaultSensor(65562) to get direct access to the HRM sensor.

To access and enable infra red light:

  1. Use at Manifest

    uses permission android:name="android.permission.BODY_SENSORS"/>

  2. implement SensorEventListener at Activity

  3. To enable red infrared light use code:

     public void enableHeartRate(){
    
        SensorManager mSensorManager = ((SensorManager)getSystemService(SENSOR_SERVICE));
        Sensor mHeartRateSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE);
    
        mSensorManager.registerListener(this,mHeartRateSensor, SensorManager.SENSOR_DELAY_NORMAL);
    }
    
    @Override
    public void onSensorChanged(SensorEvent event) {
    
        if (event.sensor.getType() == Sensor.TYPE_HEART_RATE) {
            String msg = "" + (int)event.values[0];
    
            Log.d(TAG, msg);
        }else{
            Log.d(TAG, "Unknown sensor type");
        }
    }
    
    @Override
    public void onAccuracyChanged(Sensor sensor, int i) {
    
    } 
    
  4. Check Log for results ;)

Samsung has released an SDK called SensorExtension. You must apply for it and they will send you an email with the zip file.

http://developer.samsung.com/galaxy#sensor-extension

SensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE)

works well.

But

This sensor requires permission android.permission.BODY_SENSORS. It will not be returned by SensorManager.getSensorsList nor SensorManager.getDefaultSensor if the application doesn't have this permission.

(from the documentation)

So if you readers tried getDefaultSensor without success, this is likely to be the error.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!