Skip to content
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Mist android boilerplate

This is a empty android boilerpalete to start a mist android project.

Please learn more about the Mist concepts on


The example source code is licensed under Apache 2.0. For the example code to be useful, you will need to have the MistApi aar libraries from ControlThings. These libraries require a valid license from ControlThings Oy Ab so that they can be used.

Getting Started


For the moment you will need acces to Controlthings Artifactory server, to get the MistApi.

##Credentials for Artifactory server

Create a fille in HOME_DIR/.gradle an add this lines:



Open the project in android studio and it should be ready to go.

The example application does nothing else but starts Mist service, and queries Wish and Mist versions.

How to use MistApi in existing projects

##Configure Gradle

In your top level build.gradle file add a reference to aritfactory:

allprojects {
    repositories {
        maven {
            url ""
            credentials {
                username = "${integrator_username}"
                password = "${integrator_password}"

In your app build.gradle import MistApi:

dependencies {
  implementation 'fi.ct.mist:MistApi:0.6.4'

Use of ProcessLifecycle

The Mist IoT library is built on Wish, which is a software platform for distributed systems. Wish is the responsible for opening and maintaining secure authenticated connections between the communicating peers. In Wish/Mist, the connections between peers are not request/response oriented, as in HTTP. Instead, the connections between peers are TCP socket connections, which allow for asynchronous communication between the peers. Currently, these connections are automatically managed, and the application programmer does not have to explicitly manage connections.

On Android, in order to use Mist API, the Mist service must be started first. The Wish core is started automatically when Mist service is started. Likewise, Wish core is stopped when Mist service is stopped.

When ever a Mist/Wish Android app becomes the "foreground app" on the of the Android system, the Mist service should be started. When the service is running, Wish automatically attempts to maintain connections to the remote peer(s) that it knows of.

As active TCP connections consume battery, the Wish core should be stopped when the app is no longer used by the user, i.e. it is no longer the foreground app.

To be able to start the Wish core when app comes into foreground, and stop Wish core when the app goes to the background, its preferred to use the ProcessLifecycleOwner because it helps with tracking the state of the whole app.

In your app build.gradle import:

dependencies {
  implementation 'android.arch.lifecycle:extensions:1.1.1'

In Launcher activity onCreate add a observer:

    protected void onCreate(Bundle savedInstanceState) {
        ProcessLifecycleOwner.get().getLifecycle().addObserver(new AppLifecycleListener());

Create a Lifecycle Listener Class:

class AppLifecycleListener implements LifecycleObserver {
    public void onMoveToForeground() {}

    public void onMoveToBackground() {}

Start the Mist service

On Android, Mist runs on a android service and uses an AddonReceiver for connection and disconnection info.

Add the AddonReciver to the class:

public class MainActivity extends AppCompatActivity implements AddonReceiver.Receiver

In onCreate create a mist intent and add the receiver to it:

protected void onCreate(Bundle savedInstanceState) {

  ProcessLifecycleOwner.get().getLifecycle().addObserver(new AppLifecycleListener());

  Intent mistService = new Intent(this, Service.class);
  AddonReceiver mistReceiver = new AddonReceiver(this);
  mistService.putExtra("receiver", mistReceiver);

Add onConnected (will be called when mist is ready and you can use the api):

    public void onConnected() {

Add onDisconnected (Will be called when the mist Service is stoped):

    public void onDisconnected() {

Start the mist service in onMoveToForeground:

public void onMoveToForeground() {

Stop the service in onMoveToBackground:

public void onMoveToBackground() {

Making MistApi requests

(To be continued...)


A minimal starting point for Mist based Android apps, with some sample code in separate branch




No releases published


No packages published