Languages

Menu
Sites
Language
[Web applicaiton]Get Hrm data from Gear S3

Good day developers.


I'm trying to Hrm detecting Web application for this vacation.

It's based on open source from Samsung HelloAccesary and HeartRateMonitor sample.

My purpose is detecting Heartreate, also it passes data to my Phone.

So, Phone(OS is Android)'s apk will compare rate, if the data over '120', then it make events.

But problem is apk can't distinguish the Rate. It always distinguish 'message' is bigger than 'heart_attack_rate'.

However, the value is low.

 

If you can help me, please give som advice 

Thnak you.

ps. at the below, there's code.

 

public int cmp_number(String num1, String num2)

 

{ int store_num = num1.compareTo(num2); return store_num;} //Function, which compare two String values

 

 

// 180806 public void onReceive(int channelId, byte[] data)

{ final String message = new String(data);

String heart_attack_rate="120"; //heart attack rate

int cmnumber=cmp_number(heart_attack_rate,message); //compare to values

if (cmnumber<0)

{ addMessage("Detected Hrm Rate: ", message);

addMessage("Detected number: ", Integer.toString(cmnumber)); }//normal state

else

{ updateTextView("Heart attack!!");

addMessage("Heart attack happened: ", message);

addMessage("Detected number: ", Integer.toString(cmnumber));// for looking compareto() value

} }//heart attak happen

Edited by: 현철 조 on 07 Aug, 2018

Responses

4 Replies
Armaan-Ul- Islam

String.compareTo() compares lexicographically (based on difference of character value), This is not what you are looking for.

To compare two numbers, Parse both Strings into Integer value first, then take decision.

Try this Code Snippet:

public static int cmp_number(String num1, String num2) {

    int num1Int = Integer.parseInt(num1);
    int num2Int = Integer.parseInt(num2);

    if(num1Int > num2Int)
        return -1; //greater than range
    else
        return 1;  //less than range
}

 

현철 조

Hi, thank you for your help.

 

I took your advise, and tried to fix it, but it occured error and stop running.

Maybe it is related with DynamicArray.

 

Samsung's HelloAccesary source uses DynamicArray for saving data which comes from Gear S3.

They use Collections.synchronizedList for String.

 

Have a good day

Armaan-Ul- Islam

I'm assuming you getting HRM data as byteArray (byte []).

In that case, Create a new String sending the byte array to Constructor. Code Sample:

public static int cmp_number(String num1, String num2) {

    int num1Int = Integer.parseInt(num1);
    int num2Int = Integer.parseInt(num2);

    if(num1Int > num2Int)
        return -1; //greater than range
    else
        return 1;  //less than range
}


// 180806 public void onReceive(int channelId, byte[] data)
{ 
    final String message = new String(data,StandardCharsets.UTF_8);
    String heart_attack_rate="120"; //heart attack rate

    int cmnumber=cmp_number(heart_attack_rate,message); //compare to values
......}

 

A Relevant Post on Stack Overflow.

Armaan-Ul- Islam

Hello 현철 조 , did setting the encoding as 'StandardCharsets.UTF_8' worked out for you ? You might print the byte [] data for further understanding.

Please share current status here.