Ganesh Pokale
Ganesh Pokale

Reputation: 1594

Radius Network Beacon Library 2.0 (AltBeacon) unable to detect Beacons

Hello I'm currently using Radius Network Beacon SDK but unable to detect my beacons. In didRangeBeaconsInRegion(Collection beacons, Region region) collection object size is 0

Please help me!!

RangingActivity Code-

import java.util.Collection;
import android.app.Activity;
import android.os.Bundle;
import android.os.RemoteException;
import android.util.Log;
import android.widget.EditText;
import org.altbeacon.beacon.AltBeacon;
import org.altbeacon.beacon.Beacon;
import org.altbeacon.beacon.BeaconConsumer;
import org.altbeacon.beacon.BeaconManager;
import org.altbeacon.beacon.BeaconParser;
import org.altbeacon.beacon.RangeNotifier;
import org.altbeacon.beacon.Region;

public class RangingActivity extends Activity implements BeaconConsumer {
  protected static final String TAG = "RangingActivity";
private BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_ranging);

    beaconManager.bind(this);
    beaconManager.debug = true;
}
@Override 
protected void onDestroy() {
    super.onDestroy();
    beaconManager.unbind(this);
}
@Override 
protected void onPause() {
    super.onPause();
}
@Override 
protected void onResume() {
    super.onResume();
}

@Override
public void onBeaconServiceConnect() {
    beaconManager.setRangeNotifier(new RangeNotifier() {
    @Override 
    public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
        if (beacons.size() > 0) {
            EditText editText = (EditText)RangingActivity.this
                    .findViewById(R.id.rangingText);
            Beacon firstBeacon = beacons.iterator().next();
            logToDisplay("The first beacon "+firstBeacon.toString()+" is about "+firstBeacon.getDistance()+" meters away.");
        }
    }



    });

    try {
        beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null));
        //beaconManager.updateScanPeriods();
    } catch (RemoteException e) {   }
}
private void logToDisplay(final String line) {
    runOnUiThread(new Runnable() {
        public void run() {
            EditText editText = (EditText)RangingActivity.this
                    .findViewById(R.id.rangingText);
            editText.append(line+"\n");             
        }
    });
}

}

Upvotes: 1

Views: 2044

Answers (2)

Micha&#235;l van D.
Micha&#235;l van D.

Reputation: 13

You need to call the onBeaconConnect() in your onCreate function

protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_ranging);

  beaconManager.bind(this);
  beaconManager.debug = true;

  onBeaconConnect()
}

Upvotes: 0

Fab
Fab

Reputation: 1564

You need a custom Parser to properly recognize that beacons.

Take a look at this answer:

Is this the correct layout to detect iBeacons with AltBeacon's Android Beacon Library?

Upvotes: 4

Related Questions