IT Nerd Space

How to run Android Java code from Tasker

How to run Android Java code from Tasker

How to run Android Java code from Tasker

When it comes to Automation in Android, there is no doubt that Tasker is the absolute king. Although I admit the UI is not fancy — at all,  and the learning curve is quite harsh, Tasker has demonstrated being the most powerful app in the Automation space.

Tasker
Tasker
Developer: Crafty Apps EU
Price: $2.99

One of the little know features of Tasker is the ability to run Android Java code, sort of.

That requires some learning, as everything in Tasker, but can prove very useful to further extend Tasker possibilities.

Let see a simple example, to illustrate the concept. Let say we want to enable Bluetooth. The corresponding Android Java code would be something like :

In Tasker we would use a couple of Java Function actions that we put in a Tasker task :

First:

BluetoothAdapter bta = BluetoothAdapter.getDefaultAdapter();

Then:

bta.enable();

This is the resulting Tasker task:

Bluetooth Enable (71)
 A1: Java Function [ Return:bta Class Or Object:BluetoothAdapter Function:getDefaultAdapter
{BluetoothAdapter} () Param: Param: Param: Param: Param: Param: Param: ] 
 A2: Java Function [ Return: Class Or Object:bta Function:enable
{boolean} () Param: Param: Param: Param: Param: Param: Param: ]

This is very powerful and can unleash some new possibilities.

Say you want to enable LinkedIn synchronization on WiFi only. Tasker has no native actions to handle Android accounts synchronization. You need to access the ContentResolver Java objects and methods. This is something  you can do with Tasker! I’ll detail this example in a future post.