I'm currently working on a android app that detects nearby beacons, i'm using the AltBeacon API, i tried a modified version of the Ranging Example code given here.
Here is my code
public class MainActivity extends Activity implements BeaconConsumer {
protected static final String TAG = "RangingActivity";
private BeaconManager beaconManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BeaconManager.setsManifestCheckingDisabled(true);
beaconManager = BeaconManager.getInstanceForApplication(this);
beaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout("m:3-4=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
beaconManager.bind(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
beaconManager.unbind(this);
}
@Override
public void onBeaconServiceConnect() {
beaconManager.setRangeNotifier(new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
if (beacons.size() > 0) {
Log.i(TAG, "The first beacon I see is about "+beacons.iterator().next().getDistance()+" meters away.");
}
}
});
try {
beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null));
} catch (RemoteException e) { }
}
}
i added this line
BeaconManager.setsManifestCheckingDisabled(true);
because otherwise the application crashes at the start. ref
and i added a beaconParser to parse my beacons (iBeacon layout)
beaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout("m:3-4=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
The probleme is that i can't get any response in the logcat terminal, it's like if it can't detect my beacons.
I am using a motorola Moto G (3rd Gen) with Android 6.0, and i have given the necessary permissions
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
any ideas what could cause the issue ?