Extension: - Acoustic Warning exceeding specific Heart Rate (Bluetooth 4.0)

Started by benuli, March 24, 2014, 13:17:36

0 Members and 2 Guests are viewing this topic.

benuli

is it possible to write such an acoustic warning as an extension with LocusAPI? thanks in advance!
  •  

Menion

Hello

I think it is and it should be quite simple.

Locus offers over API feature called "Periodic updates". This means that over API you are able (over BroadCast receiver) receive every seconds current state from Locus. This means also current meassured HRM values (it's hidden in location object).

So with this knowledges, you may do whatever you want ...
- Official help (ideas, questions, problems): help.locusmap.eu
- Advanced topics, sharing of knowledges: you're here!
- LM 4 Beta download, LM 4 Release download
  •  

benuli

thanks, that would be a nice little project. I hope I get some time...;-)
  •  

Menion

you are welcome. I always gladly help with some add-ons developing so if there will be something I may help, feel free to write me
- Official help (ideas, questions, problems): help.locusmap.eu
- Advanced topics, sharing of knowledges: you're here!
- LM 4 Beta download, LM 4 Release download
  •  

benuli

good and simple to install API with examples. I wrote some test code in the samples EventReceiver.onUpdate(...) and I can see my heartrate, very nice.
Is it possible to enable Bluetooth 4.0 Heartereate Monitor in Locus with your API, so that I can start TrackRecording and Heartrate Monitoring with one single 'click' in a simple App?
  •  

Menion

Hello benuli,

good to hear there were no problems with making API work. Perfect.

What you need is a feature that is already missing in Locus itself. I have in plan improve a lot small panel at bottom of screen that control track record and together with it improve whole track recording configuration. Unfortunately it will take some time.

May you post it to our Help Desk where we collect ideas? When I'll work on this, I'll for sure do something with it. Unfortunately it will take some time (probably during July)
- Official help (ideas, questions, problems): help.locusmap.eu
- Advanced topics, sharing of knowledges: you're here!
- LM 4 Beta download, LM 4 Release download
  •  

benuli

Sorry, but I have a basic Android question: I write a static BroadcastReceiver that starts a Sound (with an IntentService or so) if a specific max heartrate is reached. But how to configure this max heartrate? In my static BroadCastreceiver I can't access the TextView of my MainActivity where the user can insert a Max HeartRate...? With a Dynamic BroadcastReceiver there is no problem, but if my Application dies in Background even the dynamic BroadcastReceiver dies...?
  •  

Menion

Hello Benuli

I think there is missing one basic rule that's need to keep on mind. You cannot trust Android that your app will survive even a minute. This means, that all information that are important for you, have to be stored somewhere.

In your case, if you want an application that will notify about some HRM values, I should suggest
1. one main activity where you set all required parameters
2. one global broadcast receiver (by global I mean defined in Manifest file!, not registered in your activity)

In your activity, set all required parameters and store these parameters in private app settings - more here http://developer.android.com/training/basics/data-storage/shared-preferences.html

In your Broadcast receiver just read these data and handle received Intent from Locus. Important is to register this receiver in your manifest. In this case, you should receive intent everytime no matter if system killer your app or not.

Hope this helps. Feel free to ask, I'll gladly help
- Official help (ideas, questions, problems): help.locusmap.eu
- Advanced topics, sharing of knowledges: you're here!
- LM 4 Beta download, LM 4 Release download
  •  

benuli

thanks! This helps. I didn't know about the shared preferences. I try this way.
  •  

benuli

Good Morning.
One more question: onReceive(...) is called very often, more than once per second. How to obtain doing the work in my BroadcastReceivers onReceive method for example only every five seconds? I have read that I should not do  long tasks in onReceive. thanks in advance.
  •  

Menion

Hello,

is it really more then once per second? There is timer set exactly on 1 second. If it's less, then there is some problem in Locus.

Anyway you do not need to proceed all received intents. Just do some quick check on time of events and use only these you wants. Like

long lastHandledEvent = 0L;

private void handleIntent(Intent data) {
  if (System.currentTimeMillis() - lastHandledEvent < 5000) {
     // do not handle, too early
     return;
  }

  lastHandledEvent = System.currentTimeMillis();
  // now handle it ....
}


just small example.

Suggestion "not to do too much work directly in receiver" has it's reasons. You can't do too much work from receiver if you use Global receiver. Because you do not know if any activity or service run and you also cannot be sure, that you are just in UI thread or in some bg thread. Because of this is better to forward received data to any activity or better to any service.

But if you really want only notification or some other quite simple tasks, I think there will be absolutely no problem to do it directly from receiver. Anyway best is to try and you will see.
- Official help (ideas, questions, problems): help.locusmap.eu
- Advanced topics, sharing of knowledges: you're here!
- LM 4 Beta download, LM 4 Release download
  •  

benuli

Thank you, it works. If somebody else wants to have this 'addon' I think I have to remove some 'Hello Worlds' ;-) and make an Icon. It's my first android app, so I have to learn how to publish this app.
  •  

Menion

Good to hear.

If you want some test from Locus users, you may firstly try to publish it here http://forum.locusmap.eu/index.php?board=53.0

If there will be any interested users, I'm sure you get some feedback.
- Official help (ideas, questions, problems): help.locusmap.eu
- Advanced topics, sharing of knowledges: you're here!
- LM 4 Beta download, LM 4 Release download
  •  

matmas

I'm interested trying your app!
Let me know if you finalized it or not. I'll not blame you even if my battery goes dead in five minutes :-D
  •