Skip to content
Switch branches/tags
Go to file

MetaWear Android API

The MetaWear Android API is a library for interacting with MbientLab's sensor boards on an Android device. A minimum of Android 7.0 (SDK 24) is required to use this library, however for the best results, it is recommended that users be on Android 10 (SDK 29) or higher.


Adding Compile Dependency

To add the library to your project, first, update the repositories closure to include the MbientLab Ivy Repo in the project's
build.gradle file.

repositories {
    ivy {
        url ""
        layout "gradle"

Then, add the compile element to the dependencies closure in the module's build.gradle file.

dependencies {
    compile 'com.mbientlab:metawear:3.8.1'

If you are using SDK v3.3 or newer, you will need to enable Java 8 feature support the module's build.gradle file. See this page in the Android Studio user guide.

Declaring the Service

Once your project has synced with the updated Gradle files, declare the MetaWear Bluetooth LE service in the module's AndroidManifest.xml file.

    android:theme="@style/AppTheme" >

    <service android:name="" />
    <!-- Other application info below i.e. activity definitions -->

Binding the Service

Lastly, bind the service in your application and retrain a reference to the service's LocalBinder class. This can be done in any activity or fragment that needs access to a MetaWearBoard object.

import android.content.*;
import android.os.Bundle;
import android.os.IBinder;


public class ExampleActivity extends Activity implements ServiceConnection {
    private BtleService.LocalBinder serviceBinder;

    protected void onCreate(Bundle savedInstanceState) {

        ///< Bind the service when the activity is created
        getApplicationContext().bindService(new Intent(this, BtleService.class),
                this, Context.BIND_AUTO_CREATE);

    public void onDestroy() {

        ///< Unbind the service when the activity is destroyed

    public void onServiceConnected(ComponentName name, IBinder service) {
        ///< Typecast the binder to the service's LocalBinder class
        serviceBinder = (BtleService.LocalBinder) service;

    public void onServiceDisconnected(ComponentName componentName) { }