4

In the Samsung's programming guide (pages 77 - 81) there is a reference on how to set and get the heart rate information using the S Health Service SDK. However, I was looking to directly access the Galaxy S5's heart rate sensor, the same way you are able to access the accelerometer, gyroscope, light sensor, among other sensors. I found this example for the samsung gear live, but I cannot find any example for Galaxy S5.

Is it possible to directly access the Galaxy S5's heart rate sensor? Does anyone has a code example on how to do it?

Thank you.

Community
  • 1
  • 1
user3427013
  • 1,039
  • 1
  • 13
  • 28
  • This may help you: http://developer.samsung.com/forum/board/thread/view.do?boardName=SDK&messageId=269251 – PurkkaKoodari Sep 07 '14 at 17:35
  • Thank you your answer. I've checked that forum thread but it only provides information on how to get heart rate info from the S Health Service SDK. I need to directly access the heart rate sensor in real time the same way you are able to do it using the accelerometer, gyroscope, light sensor, among other sensors. – user3427013 Sep 07 '14 at 17:37
  • What output do you get with the code in the question you linked? (The one that shows all sensors.) And did you include the `BODY_SENSORS` permission as suggested? – PurkkaKoodari Sep 07 '14 at 17:38
  • I don't have a galaxy s5. I'm just wondering if the same code used for the galaxy gear can be used to access the galaxy s5 heart rate sensor as well? Thank you. – user3427013 Sep 07 '14 at 17:40
  • Why would you expect it to _not_ work the same? – PurkkaKoodari Sep 07 '14 at 17:42
  • Since they are different devices, I'm wondering if the code works the same way for both. :S Have you tried the code in the Galaxy S5? I would like to be certain of it. Thank you for your answer. – user3427013 Sep 07 '14 at 17:51
  • I don't have one either. I'd recommend getting one (or borrowing a friend's, for example) if you want to create S5-specific code. – PurkkaKoodari Sep 07 '14 at 17:52

5 Answers5

1

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

VD63
  • 133
  • 1
  • 9
1

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.
Waldi
  • 101
  • 1
  • 3
1

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 ;)

Farmaker
  • 2,700
  • 11
  • 16
0

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

eSquirel
  • 41
  • 11
0
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.

Nicolai Weitkemper
  • 403
  • 1
  • 9
  • 18