How I Make Android Widgets
One of the great things about Android, is that you're empowered to customise your device to suit your needs, based on the ideal that your phone should be more than a tool, but also something you enjoy using and something that matches you.
This is a short tutorial that describes how to create a custom homescreen widget that will pull data from an API, that you can customise to look however you'd like.
Step 1
You will need:
Step 2
In Tasker, you will need to set up a profile that runs when you want your data to update. For this example, we'll create one that runs every 15 minutes.
Step 3
Next, create a task for that profile, we'll call ours "Fetch Data". This task will run every 15 minutes.
In our task, we can create a HTTP Request action, that will fetch data from an endpoint and let us access it. For this example I'll be using Wordnik's API to fetch the word of the day. The endpoint we can use is https://api.wordnik.com/v4/words.json/wordOfTheDay?api_key=API_KEY
, which will return a json object similar to the following:
1{
2 "word": "fortition",
3 "definitions": [],
4 "examples": [],
5 "publishDate": "2021-12-05T03:00:00.000Z",
6 "note": "The word 'fortition' comes from a Latin word meaning 'strong'."
7}
Step 4
Then after our HTTP Request action, we can add a KWGT Send Variable action from Plugins → KWGT. Tasker automatically parses JSON in variables, so based on our JSON above, we can use %http_data.word
to get the word of the day.
Note that this API requires a key, which we put in our request above as %APIKEY
. We need to set that before our task will run, so visit the VARS tab in tasker and paste in your API key.
Now, run your task, and we can move to KWGT to create our widget.
Step 5
First, add a KWGT widget to your homescreen, and resize it how you'd like. Then tap the widget you just created and click "Create" to make a new widget. You can customise it however you'd like; for this example I just created a white background with some black text on it.
For the text, I've used a formula that pulls our word
variable that we sent from Tasker and displays it in our widget.
Your widget is now complete! Check out all the different types of shapes and fonts that KWGT supports, you can add multiple data points to your widget or customise it with colours.
Last edited June 3, 2023