Mnubo Android SDK

This Android library is used to quickly build Android application using the Mnubo API.

License

License

GroupId

GroupId

com.mnubo
ArtifactId

ArtifactId

sdk-android
Last Version

Last Version

3.0.1
Release Date

Release Date

Type

Type

aar
Description

Description

Mnubo Android SDK
This Android library is used to quickly build Android application using the Mnubo API.
Project URL

Project URL

https://github.com/mnubo/mnubo-Android-SDK
Source Code Management

Source Code Management

https://github.com/mnubo/mnubo-Android-SDK

Download sdk-android

How to add to project

<!-- https://jarcasting.com/artifacts/com.mnubo/sdk-android/ -->
<dependency>
    <groupId>com.mnubo</groupId>
    <artifactId>sdk-android</artifactId>
    <version>3.0.1</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.mnubo/sdk-android/
implementation 'com.mnubo:sdk-android:3.0.1'
// https://jarcasting.com/artifacts/com.mnubo/sdk-android/
implementation ("com.mnubo:sdk-android:3.0.1")
'com.mnubo:sdk-android:aar:3.0.1'
<dependency org="com.mnubo" name="sdk-android" rev="3.0.1">
  <artifact name="sdk-android" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.mnubo', module='sdk-android', version='3.0.1')
)
libraryDependencies += "com.mnubo" % "sdk-android" % "3.0.1"
[com.mnubo/sdk-android "3.0.1"]

Dependencies

compile (5)

Group / Artifact Type Version
com.squareup.okio : okio jar 1.13.0
com.squareup.okhttp3 : okhttp jar 3.8.1
joda-time : joda-time jar 2.9.4
com.fasterxml.jackson.core : jackson-databind jar 2.8.4
com.fasterxml.jackson.datatype : jackson-datatype-joda jar 2.8.4

Project Modules

There are no modules declared in this project.

Maven Central Build Status

Introduction

This SDK provides you with a wrapper to use the mnubo's service easily from your Android application. Basically this SDK sets up a connection with the mnubo API and ensure oAuth2 headers are present in your calls to it.

Installation & Configuration

The library can be picked up from Github or MavenCentral. Add the aar to your project dependencies or add this Gradle dependency to your build file :

// Using gradle and maven dependency resolution
compile('com.mnubo:sdk-android:2.0.0@aar') {
    transitive = true
}

You also need to exclude the following files from the packaging to avoid duplicate exception during build :

packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
        exclude 'META-INF/ASL2.0'
    }

The SDK must be initialized (only once). To do so, call the init() function in your application startup. For example :

@Override
public void onCreate() {

    Mnubo.init(
        getApplicationContext(),
        MnuboSDKConfig.withUrlAndKey("https://sandbox.api.mnubo.com", "CONSUMER_KEY"),
        new AuthenticationProblemCallback() {
            @Override
            public void onError() {
                //do something when login fails
            }
        });
}

Key

The CONSUMER_KEY is provided to you by mnubo. The SDK can only be used by a logged in owner. If no owner logs into the app, all operations will give you an access_denied.

Using the SDK

Once initialized and logged in, you can get an instance of the MnuboApi and use it to interact with mnubo servers.

MnuboApi mnuboApi = Mnubo.getApi();

Logging in

You can sign in on behalf of the user and start using the SDK to it's fullest by calling the API like this (note that this call performs Network IO, and you should not do it on the main thread):

boolean succress = Mnubo.logIn(username, password);

Check if user is logged in

You can know if the user is logged in like this :

boolean loggedIn = Mnubo.isLoggedIn();

Available API operations

All operations will perform a token refresh if the current access_token has expired. Operations have both synchronous and asynchronous signature.

Synchronous request are performed on the current thread. Asynchronous request runs in an AsyncTask and the result is passed through the callback if it is available.

Asynchronous call require a callback the will be invoked when the operation has completed:

Mnubo.getApi().getEventOperations().sendEventsAsync(deviceId, events, new CompletionCallback<Void>() {
    @Override
    public void onSuccess(Void result) {
        //it worked
    }

    @Override
    public void onFailure(MnuboException exception) {
        //it didn't work
    }
});

Data store

The SDK comes with a store that allows you to store data. Currently, the store only allows to save events.

Mnubo.getStore().writeEvents(deviceId, events);
//or
Mnubo.getStore().readEvents(new MnuboStore.ReadEventsCallback() {
    @Override
    public void process(String deviceId, List<Event> readEvents) {
        Mnubo.getApi().getEventOperations().sendEventsAsync(deviceId, readEvents, new CompletionCallback<Void>() {
            @Override
            public void onSuccess(Void result) {
                //success
            }

            @Override
            public void onFailure(MnuboException exception) {
               //failed
            }
        });
    }
    @Override
    public void error(File fileInError) {
        //the file could not be read or does not contains appropriate data
    }
});

The mnubo Android SDK allows you to write object to the disk. The default location is the application cache directory (using the Android context provided in the init call) but you can use something else you can provide another directory if you want:

Mnubo.getStore().setRootDir(new File("/where/you/need"));
Mnubo.getStore().setSizeLimit(250); //default is 200 files

Examples

Assuming you are logged in, this is how you post events:

List<Event> myEvents =
    Collections.singletonList(
        Event.builder()
        .eventType("my_event_type")
        .timeserie("timeserie1", "value")
        .build()
    );
Mnubo.getApi().getEventOperations().sendEventsAsync(deviceId, myEvents, new CompletionCallback<Void>() {
    @Override
    public void onSuccess(Void result) {
        showProgress(false, mProgressView, mUpdateWindTurbineView);
        Toast.makeText(getApplicationContext(), "It works, marvelous", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onFailure(MnuboException exception) {
        showProgress(false, mProgressView, mUpdateWindTurbineView);
        Toast.makeText(getApplicationContext(), "It didn't work, too sad.", Toast.LENGTH_SHORT).show();
        if (exception instanceof MnuboNetworkException) {
            Mnubo.getStore().writeEvents(deviceId, events);
        }
    }
});

Demo

There is an application demo here that you can look at for example on how to use the SDK.


Important notes

Sources, Javadoc and the library itself are located here.

Extensive documentation is available in the generated Javadoc.

com.mnubo

mnubo SmartObjects™ GitHub

mnubo's SmartObjects Cloud provides Big Data Analytics for the Internet of Things.

Versions

Version
3.0.1
3.0.0
2.1.0
2.0.0
1.3.0
1.2.1
1.2.0
1.1.6
1.1.5
1.1.4
1.1.3
1.1.2
1.1.1
1.1.0
1.0.3
1.0.2
1.0.1