Package org.altbeacon.beacon
Interface BeaconConsumer
-
public interface BeaconConsumerAn interface for an AndroidActivityorServicethat wants to interact with beacons. The interface is used in conjunction withBeaconManagerand provides a callback when theBeaconServiceis ready to use. Until this callback is made, ranging and monitoring of beacons is not possible. In the example below, an Activity implements theBeaconConsumerinterface, binds to the service, then when it gets the callback saying the service is ready, it starts ranging.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); } @Override protected void onDestroy() { super.onDestroy(); beaconManager.unbind(this); } @Override public void onBeaconServiceConnect() { beaconManager.setRangeNotifier(new RangeNotifier() { @Override public void didRangeBeaconsInRegion(Collectionbeacons, 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) { e.printStackTrace(); } } } - See Also:
BeaconManager
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleanbindService(Intent intent, ServiceConnection connection, int mode)Called by the BeaconManager to bind your BeaconConsumer to the BeaconService.ContextgetApplicationContext()Called by the BeaconManager to get the context of your Service or Activity.voidonBeaconServiceConnect()Called when the beacon service is running and ready to accept your commands through the BeaconManagervoidunbindService(ServiceConnection connection)Called by the BeaconManager to unbind your BeaconConsumer to the BeaconService.
-
-
-
Method Detail
-
onBeaconServiceConnect
void onBeaconServiceConnect()
Called when the beacon service is running and ready to accept your commands through the BeaconManager
-
getApplicationContext
Context getApplicationContext()
Called by the BeaconManager to get the context of your Service or Activity. This method is implemented by Service or Activity. You generally should not override it.- Returns:
- the application context of your service or activity
-
unbindService
void unbindService(ServiceConnection connection)
Called by the BeaconManager to unbind your BeaconConsumer to the BeaconService. This method is implemented by Service or Activity, and You generally should not override it.
-
bindService
boolean bindService(Intent intent, ServiceConnection connection, int mode)
Called by the BeaconManager to bind your BeaconConsumer to the BeaconService. This method is implemented by Service or Activity, and You generally should not override it.- Returns:
- the application context of your service or activity
-
-