12. November 2016

I’ve created Android Widget for controlling ESP8266 relay the last week.

The only problem was that the widget was not visible on Lenovo K5.

I was searching for the root cause using method: “Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth.”

I grabbed several other repositories with widgets from Github. Widgets from other projects were working.

To keep long story short. Here is the configuration when widget does not appear:

Here is the configuration when widget properly appears:

Can you spot the difference?

It is very simple. Large number of Android devices displays widget just after installation even when using the first configuration. The problem with Lenovo K5 is that it does not register widget just after installation via adb. You need to launch MainActivity and only after that UI subsystem displays the widget.

Original code from Obaro’s repo is without MainActivity. I took inspiration from Udacity’s Android widget. After I’ve added MainActivity and several other small files into the project the widget appeared even on Lenovo K5.

That was the easy part. I was able to control relay directly from mobile phone via web browser which was not very convenient. The widget would serve better.

Writing a widget for Android was real challenge. There is very little documentation about it and even Android Studio does not contain template for writing widget. I spent several hours learning how widget works. It is very different from common application.