Reputation: 11
I'm working on an Android
app that detects an iBeacon
. Now my problem is that in the LogCat
I can see the correct name of the beacon together with the IP-address
BtGatt.btif btif_gatc_update_properties BLE device name=.. BtGatt GattService onScanResult() IP-address
But the onBeaconServiceConnect()
method still enters the else
part as the collection ( Size
is 0). I have already read the thread concerning this topic in here and searched the internt but couln't find an answer.
My Code:
public class RangingActivity extends Activity implements BeaconConsumer {
protected static final String TAG = "RangingActivity";
private BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);
private BluetoothAdapter btAdapt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ranging);
beaconManager.setBackgroundScanPeriod(1000);
beaconManager.bind(this);
}
@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() {
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
logToDisplay("Number of beacons detected: "+beacons.size());
if (beacons.size() > 0) {
EditText editText = (EditText)RangingActivity.this
.findViewById(R.id.rangingText);
Beacon firstBeacon = beacons.iterator().next();
logToDisplay("The first beacon "+firstBeacon.toString());
}else{
logToDisplay("No beacon");
}
}
});
try {
beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null));
} 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: 140
Reputation: 65025
The log line you mention in LogCat indicates that Android's bluetooth stack saw a Bluetooth LE device. It does not mean that the bluetooth device it saw is a recognizable beacon.
The most likely explanation is that you do not have any beacons transmitting that the library will recognize. Understand that by default, the Android Beacon Library only detects AltBeacons, a transmission format that is intellectual-property free. If you want the library to detect proprietary beacons, then you need to configure it with a custom BeaconParser
. This is actually very easy to do. Carefully read the documentation for the setBeaconLayout
method on how to do this.
If this does not solve your problem and you wish to debug this further, try enabling debug logging in the library to get more information in LogCat. You can do this by adding a line to your onCreate
method:
beaconManager.setDebug(true);
Upvotes: 0