Third Party Apps


AutoApps can help any Android app trigger events in Tasker very easily.

Tasker Event Generation in 3 steps:

  1. Add this file to your Android App’s project
  2. Call AutoAppsThirdParty.authorize(context); from anywhere in your code (this will make AutoApps show a notification asking the user to authorize your app to send AutoApps commands)
    screencapture
  3. Call AutoAppsThirdParty.sendCommand(context, “mycommand”); (this will send the “mycommand” command to AutoApps and trigger any appropriate “AutoApps Command” event condition in Tasker if the user authorized your app on the previous step)

Check out some apps that already implement this system

Custom Commands

You can register custom commands for your app so that the user can easily select the command and have access to variables you might want to make available.

This is an example of what the “AutoApps Command” Tasker condition setup looks like when an app has created several custom third party commands.

screencapture

Let’s go through some examples of how to set this up.

 

Simple custom command; No variables

Let’s say you want to let a user know when she/he clicked the ok button somewhere in your app. You can register a custom command like this

AutoAppsThirdParty.registerCommands(context, new AutoAppsThirdParty.RegisteredCommand("Clicked Ok", "clickedok"));

  • Clicked Ok” is the command name that the user will see
  • clickedok” is a unique id. Each custom command has its own unique id

To trigger this event in Tasker use this code in your Android App:

AutoAppsThirdParty.sendCommand(context, "clickedok");

Custom command with variables

Now let’s say you to let the user know when she/he clicked any button in your app. A nice way to do that is to generate the same command for every button, and set a variable with the button name

AutoAppsThirdParty.registerCommands(context, new AutoAppsThirdParty.RegisteredCommand("Clicked Button", "clickedbutton","buttonname"));

  • Clicked Button” is the command name that the user will see
  • clickedbutton” is a unique id for this event
  • buttonname” is the name of the variable that will be created in the entry Task of the profile. It will contain the button name

To trigger this event in Tasker use this code in your Android App:

AutoAppsThirdParty.sendCommand(context, "clickedbutton=:=ok");

This will trigger the event and create a variable called “%buttonname” in Tasker with the value “ok”

 

Custom command with variables and arrays

Finally you may want to let the user know about an event where a variable number of things happen. For example if your app is a file manager you may want to inform the user that you have written some files. You could register a custom command like this:

AutoAppsThirdParty.registerCommands(context, new AutoAppsThirdParty.RegisteredCommand("Wrote Files", "wrotefiles", true, "directory", "files"));

  • Write Files” is the command name that the user will see
  • writefiles” is a unique id for this event
  • true lets AutoApps know that the last variable name is an array
  • directory” is the name of a variable that will be created in the entry Task of the profile. It will contain the directory the files were written to
  • files” is the name of the variable array that will be created in the entry Task of the profile. It will contain a list of all the files that were written

To trigger this event in Tasker use this code in your Android App:

AutoAppsThirdParty.sendCommand(context, "wrotefiles=:=Downloads=:=screenshot.png=:=picture.jpg");

This will trigger the event and create a variable called “%directory” in Tasker with the value “Downloads” and a variable array called %files() with 2 items: “screenshot.png” and “picture.jpg”

Video of a similar example:

 

Proguard

If you use proguard to build your app for release, please add these 3 commands to your proguard file:

-keep class com.joaomgcd.common.tasker.** { *; }
-keep class com.joaomgcd.common.tasker.AutoAppsThirdParty { *; }
-keep class com.joaomgcd.common.tasker.AutoAppsThirdParty$RegisteredCommand { *; }