0

I want to display data to the textview from the database when the beacon is detected in specific distance .... the problem is it does not work or does not display anything here's my code ...

    public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {

        if (beacons.size() > 0) {           
        for (Beacon beacon: beacons) {                  
            if(beacon.getDistance() < 0.5){
              ddb();
            //Call Display data from database 
            }

Does it has something to do with ranging every second?

Is it possible to display data from the database using didRangeBeaconsInRegion?

strygwyr
  • 3
  • 2
  • You don't need the if-statement. Are you sure there is any beacon in beacons and is any beacon's .getDistance smaller then 0.5? And what is ddb? What does it do? Where are the bindings? –  Oct 04 '14 at 19:41
  • Yes I test it using the altbeacon reference app and just inserted an if statement if(beacon.getDistance() < 0.5) ... when I get closer to the beacon the app works fine and display the beacon identifiers ... the problem is when I try to replace the logtodisplay in the reference app and replace it with a proceduce ddb() that display data from the database in a textview ... It does not work and my guess is it has something to do with ranging every second .. thats why I'm asking if it is possible to display data from database using didRangeBeaconsInRegion? or is there another way to do that? – strygwyr Oct 04 '14 at 20:11

1 Answers1

0

Try adding log lines to troubleshoot like this:

for (Beacon beacon: beacons) {
   Log.d(TAG, "saw beacon:"+beacon+"  with dist "+beacon.getDistance() );
   if(beacon.getDistance() < 0.5) {
      Log.d(TAG, " calling ddb");
      ddb();
      //Call Display data from database 
   }
}

Check to see that you see the first log line, and verify that if the distance is less than 0.5 the second log line is shown.

davidgyoung
  • 63,876
  • 14
  • 121
  • 204