Why do I need the Flic app?
The fliclib works with the Flic app so that you
don't have to worry about handling the Flics, scanning the Flics,
or monitoring the communication with them. All of that is taken care of
by the Flic app.
- Download and install the Flic app. It's free and you can find it in the Google Play Store.
Connect all your Flics to the app.
That's it! Now you will be able to use the Flic Grabber and get access
to the Flics inside your own app. Don't worry, we'll go through
how this is done soon.
Create a new project or open an existing one.
The target of the project must be at least API 19 (Android 4.4).
Now open File -> New -> Import Module... and select the
fliclib-android directory which can be checked out from
Add a reference to the fliclib in the menu by clicking
File -> Project -> Structure -> app (in the left sidebar) ->
Dependencies tab -> The + button in the rightmost section -> Module
dependency -> fliclib -> OK
All imported classes are in the package io.flic.lib.
There are two important classes, FlicManager and FlicButton.
The singleton class FlicManager keeps track of all the buttons
and FlicButton represents a single button. To retrieve buttons,
we need to use the button grabber and to be able to receive
button events in the background we need to register a
Before we initiate the FlicManager we need to set app
credentials using the method FlicManager.setAppCredentials.
The most appropriate place to do this is either in the creation of the
MainActivity class or, in a larger application in the
Application class. The appId and appSecret
are unique for every application and can be generated on our
The appName should be the friendly name of your app.
We will now use the manager that can be used to grab a button from
the Flic app. The Flic app will be opened up, and the user will be
prompted to select one of his/her connected buttons. It will then
send information about the button back to our app so that we can
start using it. In an activity, this code is used to grab a button.
To receive the button object, we must feed the result into the
manager which then returns the button object. With the button object,
we register for notifications. In this example, we’re only interested
in down, up and remove events.
We are now ready to receive events. The events will be sent to a
broadcast receiver. This way the app will receive events even if the
Android system has shut down the app process. The intent name to
listen for is io.flic.FLICLIB_EVENT, which we register in the
The broadcast receiver should extend the
FlicBroadcastReceiver class. It has a method
onRequestAppCredentials which must be implemented that sets the app
credentials. Note that since the app process might be started upon an
event, the main activity is not started so it is not enough to
provide the app credentials there. We override the methods that will
be called upon receiving the corresponding events.