B4A Library ABFlicB4A library for Flic buttons

cute-as-a-button-1.png

You probably have seen these nifty little IoT Flic buttons around. They are a fun and relative cheap BLE button that allows you to do something when the button is clicked, doubleclicked or hold.

Demo video:

How to use:
1. Install the Flic app from the Google Play.
2. On their developer page, create a new app: you get a key and a secret.
3. Copy the ABFlicB4A library jar and xml to your library folder and select it in B4A

Example usage code:
B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Private flic As ABFlic
   Private Button2 As Button
   Private Button3 As Button
   Private Button4 As Button
   Private Label1 As Label
   Private Button1 As Button
   
   Private MyFlicID As String
   
   Private FlicResults As List   
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   Log("created")
   Activity.LoadLayout("1")     
   FlicResults.Initialize
   FlicResults.Add("RESULTACTION_HOLD")
   FlicResults.Add("RESULTACTION_SINGLECLICK")
   FlicResults.Add("RESULTACTION_DOUBLECLICK")
End Sub

Sub Activity_Resume
   ' your key and secret
   flic.Initialize("Flic", "d60d36a0-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "db5c2b3d-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "ABFlicTest")
End Sub

Sub Button1_Click
   flic.ForgetButton(MyFlicID)
End Sub

Sub Button2_Click
   flic.GrabButton
End Sub

Sub Button3_Click
   flic.StartListening
End Sub

Sub Button4_Click
   flic.StopListening
End Sub

Sub flic_Added(buttonID As String, Name As String)
   MyFlicID = buttonID
   Log("Added: " & buttonID)
   Label1.Text = "Added: " & buttonID & CRLF & Label1.Text
End Sub

Sub flic_Clicked(buttonID As String, wasQueued As Boolean, timeDiff As Int)
   MyFlicID = buttonID
   Log("Clicked: " & buttonID)
   Label1.Text = "Clicked: " & buttonID & CRLF & Label1.Text
End Sub

Sub flic_DoubleClicked(buttonID As String, wasQueued As Boolean, timeDiff As Int)
   MyFlicID = buttonID
   Log("DoubleClicked: " & buttonID)
   Label1.Text = "DoubleClicked: " & buttonID & CRLF & Label1.Text
End Sub

Sub flic_Holded(buttonID As String, wasQueued As Boolean, timeDiff As Int)
   MyFlicID = buttonID
   Log("Holded: " & buttonID)
   Label1.Text = "Holded: " & buttonID & CRLF & Label1.Text
End Sub

Sub flic_Removed(buttonID As String)
   MyFlicID = ""
   Log("Removed: " & buttonID)
   Label1.Text = "Removed: " & buttonID & CRLF & Label1.Text
End Sub

Sub flic_Error(err As Int)
   Log("Error: " & err)
   Label1.Text = "Error: " & err & CRLF & Label1.Text
End Sub

I'm currently working on a Desktop/Raspberry Pi version of this library, which I will share in the B4J forum later.
 

Attachments

  • ABFlicB4A1.00.zip
    48.8 KB · Views: 408

biometrics

Active Member
Licensed User
Longtime User
Just got a set of these. Does the Android device the buttons are "grabbed" to need an internet connection when your app starts up?

Does the "grabbed" configuration remain if your reboot your device?
 

biometrics

Active Member
Licensed User
Longtime User
Just got a set of these. Does the Android device the buttons are "grabbed" to need an internet connection when your app starts up?

Does the "grabbed" configuration remain if your reboot your device?

To answer my own question. I've disabled wifi and mobile data and restarted the phone. It takes a while after restarting before the buttons register, but it seems they don't need an internet connection and they do recall their settings.
 

biometrics

Active Member
Licensed User
Longtime User
I have 4 of those devices. In my opinion they are useless. And their cost is not comparable to other similar gadget.
Please share why you say so as we need buttons for a queueing solution and don't want to go ahead with these if there are issues.

What would you recommend?
 

tigrot

Well-Known Member
Licensed User
Longtime User
Hi biometrics, I say so because they have very limited range, you have no feedback if the smartphone is hidden and sometimes they don't send command(or command is not receiver by smartphone). I don't think they have a real use apart from experimental or ludic use. Someone says he can remote power on/off/dimmer light, but to do so you have to stick somewhere and this is not different from a cabled cheap dimmer, apart from draining batteries!
I don't know what you are going to experiment, but for my use(a SOS button) it was scarselly useful and I gave up.
There are bidirectional transceivers but they are usually bigger. Till a remote control is not able to give a feedback from the receiver you can never know what is going on!
 

biometrics

Active Member
Licensed User
Longtime User
And above all you have to install a support(not friendly at all) and they don't allow you to get rid of it till you buy at least 1.000 pieces of flic
In our case the buttons will be within a few meters of an Android media player so the range will be fine.

Please elaborate on your post above.

Currently we have to install their app and register each button. Then in our app you need to "grab" each button. Thereafter you just need to "listen". This seems to work well but I've only been trying them for a few days.
 

biometrics

Active Member
Licensed User
Longtime User
And above all you have to install a support(not friendly at all) and they don't allow you to get rid of it till you buy at least 1.000 pieces of flic
What do you mean by 1,000 units. Do they give you an SDK so that you don't have to use their app.
 

biometrics

Active Member
Licensed User
Longtime User
@alwaysbusy

I've used your library successfully and it's working very well. I do have a problem though ...

Our product consists of several separate .apks. One is used for setting up and configuring the product. In this .apk I use .GrabButton to select the buttons we want to use. I can see the button clicks events with the _Clicked event.

When I then run our main .apk the _Clicked events do not fire. It seems the buttons that were grabbed only fires an event in the .apk where it was called. I confirmed this by doing a grab in our main .apk and then the event fired but only for that one button and not the others that were grabbed in the other .apk.

So it seems that your library records the grabbed buttons against the .apk name and only fires the event if they match.

Is there a way to solve this? We want to do the grabbing in one .apk and the events in another .apk.
 

biometrics

Active Member
Licensed User
Longtime User
After reading the Android tutorial: https://partners.flic.io/partners/developers/android-tutorial

I tried adding intent listener (excuse my Android terminology). I've done this before for HDMI state change and that works well.

So I added this to the manifest:

B4X:
AddReceiverText(FlicListener,
<intent-filter>
    <action android:name="io.flic.FLICLIB_EVENT" />
</intent-filter>)

I added a service module (same as I did with HDMI status monitoriong) with this code:

B4X:
#Region  Service Attributes
   #StartAtBoot: False
#End Region

Sub Process_Globals

End Sub

Sub Service_Create

End Sub

Sub Service_Start (StartingIntent As Intent)
   If StartingIntent.Action = "io.flic.FLICLIB_EVENT" Then
       Log("Flic event")
   End If
End Sub

Sub Service_Destroy

End Sub

I'm only getting the grabbed button, not the others I grabbed in another .apk.

So that's not a solution. Thought I might be able to work around the problem.
 

biometrics

Active Member
Licensed User
Longtime User
Has been a *very* long time since I looked at that (wouldn't even know where my flics are :D)

I have uploaded the source code of the libraries (B4A and B4J) to my github for whoever wants to use it:

https://github.com/RealAlwaysbusy/ABFlic

My Java experience is a short 3 day course on Linda.com so this is a bit over my head. Would you mind explaining how to compile the code, then I can fiddle with it a bit. I want to see if getButtonByDeviceId might solve the problem.
 

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hi All

Does the flic app have to be installed on the phone for the Lib to work ? We just contacted Flic about using their buttons with some of our apps and they responded with this:


Please find the SDK's here https://github.com/50ButtonsEach/


Regards

John.
 
Last edited:
Top