Using MeshService

Since MeshService is the core class of the CSRMesh Android library, you will need it in your main activity. Create a global variable and bind it inside the onCreate method:

private MeshService mMeshService;
@Overrideprotected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    // Make a connection to MeshService to enable us to use its services.    Intent bindIntent = new Intent(this, MeshService.class);    bindService(bindIntent, mServiceConnection, Context.BIND_AUTO_CREATE);}

If you notice, there is an unknown variable in the previous code, mServiceConnection. This is an object that will handle the service connection. Declare it using the following code:

private ServiceConnection mServiceConnection ...

Get Building Bluetooth Low Energy Systems now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.