Android Question BroadCastReceiver & Blood Glucose Data

Discussion in 'Android Questions' started by duneplodder, Jun 15, 2015.

  1. duneplodder

    duneplodder Active Member Licensed User

    I am using an app to read my blood glucose from a continuous blood glucose meter.
    This app can broadcast each new reading which another of the developer's apps can use. All this works well.
    I would like though to intercept these readings in a B4A app. I imagine I should be able to do this using the BroadCastReceiver library. However I'm not sure where to start.
    Although the software is open source & I can view the code I don't understand Java & cannot see what is happening.

    It broadcasts every 5 minutes. Is there a way of listing any intents which are being broadcast, to try & spot the relevant one?

    Could anyone advise me as to what I should look for in the existing code?

    Sorry to be so vague.
  2. tigrot

    tigrot Well-Known Member Licensed User

    I don't thing that library has anything to do with your problem. Which is the transport for your broadcast? wi-fi or BT? The library you mentioned is about internal brodacast of messages. I understand java a little bit and I'm found of interconnections, since they where my bread in the last 30 years. If you can give more info...
  3. walterf25

    walterf25 Well-Known Member Licensed User

    I've made several apps for Blood Glucose Monitors, the first question is what is the brand of your BGM, and how does it transmit the data, through USB cable, wireless? wifi/BT?

  4. duneplodder

    duneplodder Active Member Licensed User

    Thank you both.
    Sorry, I should have explained more fully.
    I'm using a Dexcom G4 CGM. It works well with it's receiver. For anyone with Type 1 Diabetes it is life changing.
    I have also built an electronic device which converts the data transmitted from the CGM into Bluetooth. This is a great system designed by an open source developer, Stephen Black, together with an Android App (xDrip) to read & display the data. This also works well. See

    The xDrip app has an option to internally "broadcast" the data. He has another app, called "NightWatch" which can use the data.
    What I would like to do is receive this data in a B4A app for my own purposes.

    As I said xDrip is open source, so if anyone has the time the code is in Github at the link above. I've downloaded it & viewed it in Android Studio but don't know Java so have been unable to understand what the relevant code is.
  5. tigrot

    tigrot Well-Known Member Licensed User

    I have seen the code. It misses some style data so i'm unable to compile...
  6. duneplodder

    duneplodder Active Member Licensed User

    Yes I noticed that.
    In the meantime I've made a little progress, with some help. I now have the relevant strings:


    And receive this:
    Intent=Intent { act=com.eveningoutpost.dexdrip.BgEstimate flg=0x10 (has extras) }

    To be honest I'm out of my depth as I've never done anything with Intents but I'll keep reading..
  7. duneplodder

    duneplodder Active Member Licensed User

    I'm having another look at this but I'm afraid I'm struggling. This is an open

    source app which does read the broadcast data:

    This seems to be the main class which deals with received intent:

    public class IntentService extends {
    public static final String ACTION_NEW_DATA =


    public IntentService() {

      protected void onHandleIntent(Intent intent) {
      if (intent == null)

      final String action = intent.getAction();

      try {
      if (ACTION_NEW_DATA.equals(action)) {
      final double bgEstimate = intent.getDoubleExtra(Intents.EXTRA_BG_ESTIMATE,

      if (bgEstimate == 0)

      int battery = intent.getIntExtra(Intents.EXTRA_SENSOR_BATTERY, 0);

      final Bg bg = new Bg();
      bg.direction = intent.getStringExtra(Intents.EXTRA_BG_SLOPE_NAME);
      bg.battery = Integer.toString(battery);
      bg.bgdelta = (intent.getDoubleExtra(Intents.EXTRA_BG_SLOPE, 0) * 1000 * 60 *

      bg.datetime = intent.getLongExtra(Intents.EXTRA_TIMESTAMP, new Date

      bg.sgv = Integer.toString((int) bgEstimate, 10);;
      DataCollectionService.newDataArrived(this, true, bg);
      } finally {

    The data it receives is in a class called Bg defined here:

    public class Bg extends Model {
    public SharedPreferences prefs;

      @Column(name = 
    public String sgv;

      @Column(name = 
    public double bgdelta;

      @Column(name = 
    public double trend;

      @Column(name = 
    public String direction;

      @Column(name = 
    public double datetime;

      @Column(name = 
    public String battery;

      @Column(name = 
    public double filtered;

      @Column(name = 
    public double unfiltered;

    What would this class look like in B4A?

    In B4A I have been able to connect & receive the following:
    Intent=Intent { act=com.eveningoutpost.dexdrip.BgEstimate flg=0x10 (has extras) }

    But I'm completely lost as to how to use this..
    Any help would be much appreciated.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice