Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Simple Api Usage

Ryan Feline edited this page May 31, 2017 · 1 revision

Get callbacks on connectivity changes

Create Merlin (using Merlin.Builder())

merlin = new Merlin.Builder().withConnectableCallbacks().build(context);

Bind and unbind the service in your activity

@Override
protected void onResume() {
    super.onResume();
    merlin.bind();
}

@Override
protected void onPause() {
    merlin.unbind();
    super.onPause();
}

Register for callbacks

merlin.registerConnectable(new Connectable() {
        @Override
        public void onConnect() {
            // Do something!
        }
});

Retrieve current network state

Create MerlinsBeard

merlinsBeard = MerlinsBeard.from(context);

Use MerlinsBeard to retrieve the current network state

    if (merlinsBeard.isConnected()) {
        // Connected, do something!
    } else {
        // Disconnected, do something!
    }

Use MerlinsBeard to retrieve whether there is a wifi connection

    if (merlinsBeard.isConnectedToWifi()) {
        // Connected, do something!
    } else {
        // Disconnected, do something!
    }

The MerlinActivity within the demo shows a simple way to declutter Merlin from your main application code.

Clone this wiki locally