public interface CBServiceListener
In the example below, an Activity implements the CBServiceListener interface, binds to the service, then when it gets the callback saying the service is ready, it starts ranging.
public class RangingActivity extends Activity implements CBServiceListener { protected static final String TAG = RangingActivity.class.getSimpleName(); private Cubeacon client = Cubeacon.getInstance(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ranging); client.connect(this); } @Override protected void onDestroy() { super.onDestroy(); client.disconnect(this); } @Override public void onBeaconServiceConnect() { client.addRangingListener(new CBRangingListener() { @Override public void didRangeBeaconsInRegion(Listbeacons, CBRegion region) { if (beacons.size() > 0) { Log.i(TAG, "The first beacon I see is about "+beacons.get(0).getAccuracy()+" meters away."); } } }); try { client.startRangingBeaconsInRegion(new Region("com.eyro.cubeacon.region_ranging")); } catch (RemoteException e) { Log.e(TAG, "Error while starting to ranging beacons, cause : " + e); } } }
Cubeacon
Modifier and Type | Method and Description |
---|---|
boolean |
bindService(android.content.Intent intent,
android.content.ServiceConnection connection,
int mode)
Called by the Cubeacon to bind your CBServiceListener to the BeaconService.
|
android.content.Context |
getApplicationContext()
Called by the Cubeacon to get the context of your Service or Activity.
|
void |
onBeaconServiceConnect()
Called when the beacon service is running and ready to accept your commands through the Cubeacon
|
void |
unbindService(android.content.ServiceConnection connection)
Called by the Cubeacon to unbind your CBServiceListener to the BeaconService.
|
void onBeaconServiceConnect()
android.content.Context getApplicationContext()
void unbindService(android.content.ServiceConnection connection)
boolean bindService(android.content.Intent intent, android.content.ServiceConnection connection, int mode)
java.lang.SecurityException
- If it do not have permission to bind to the given service