Tasker
Home
Download
TaskerNet
Usage Examples
Pre-made Projects
FAQs
Guides
Reviews
Wiki
Plugin List
Forum
Support
Userguide (5.0+)
Index: en es fr zh
1 Page: en
More
Join
AutoApps
Developers
History
Privacy Policy
Release Notes
Next Version
Feature Requests
Report Issues
Patreon

Tasker Command System

The Tasker Command System enables a lot of flexibility when creating actions with custom behaviour.

It works in the same way as the AutoApps Command System but instead of using the AutoApps Command plugin condition you use the native Command event condition in Tasker.

For example, you could use the Power Menu Action action in Tasker to create Android 11 Power Menu action where you can launch an app. Instead of having a different task for each app ├Żou want to launch you can simply set it to send a Command like

   
       launchapp=:=Chrome
   

And then setup a profile with the Command event condition with the Command filter set to

   
       launchapp=:=*
   

and variables set to

   
       %app
   

Then in the task simply use the Launch App action and launch the app in the %app variable.

If you ever want to launch an app from anywhere else where a command can be sent you can do so by sending a command like

   
       launchapp=:=Gmail
   

to launch the Gmail app for example.

Here's what that would look like in Tasker.

This would be the Task that would setup the action:

   
    Setup Power Menu (168)
    	A1: Power Menu Action [  ID:Smart App Action:Add/Edit Type:Button Title:Chrome Subtitle:Browse the Web Icon:content://net.dinglisch.android.taskerm.iconprovider/app/com.android.chrome Command:launchapp=:=Chrome ] 
   

And this would the profile that reacted to the command:

   
    Profile: Open App With Command (169)
    	Restore: no
    	Event: Command [ Output Variables:* Command:launchapp=:=* Variables:%app Last Variable Is Array:Off ]
    Enter: Anon (170)
    	A1: Launch App [ Package/App Name:%app Data: Exclude From Recent Apps:Off Always Start New Copy:Off ] 
   

For more info please check out the AutoApps Command System where the command structure is explained in detail.

Third Party Apps

Other apps can also trigger this event.

To do that they simply need to ask for this permission in the manifest:

   
      <uses-permission android:name="net.dinglisch.android.tasker.PERMISSION_SEND_COMMAND"/>
   

If the app targets API 30 or above it also needs this permission:

   
      <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
   

Then you can add a TaskerCommand.kt file to your project with the following code:

   
      import android.content.Context
      import android.content.Intent
      import android.content.pm.PackageManager
      import android.os.Build.VERSION
      import android.os.Build.VERSION_CODES
      
      const val PERMISSION_SEND_COMMAND = "net.dinglisch.android.tasker.PERMISSION_SEND_COMMAND"
      private const val EXTRA_COMMAND = "command"
      val Context.canSendTaskerCommand get() = if (VERSION.SDK_INT < VERSION_CODES.M) true else checkSelfPermission(PERMISSION_SEND_COMMAND) == PackageManager.PERMISSION_GRANTED
      fun Context.sendTaskerCommand(command: String) {
          if (command.isEmpty()) throw RuntimeException("Empty command")
          if (!canSendTaskerCommand) throw SecurityException("No permission to send Tasker Command")
      
          val intent = Intent().apply {
              setClassName("net.dinglisch.android.taskerm", "com.joaomgcd.taskerm.command.ServiceSendCommand")
              putExtra(EXTRA_COMMAND, command)
          }
          try {
              if (VERSION.SDK_INT < VERSION_CODES.O) startService(intent) else startForegroundService(intent)
          } catch (t: Throwable) {
              throw RuntimeException("Couldn't send command", t)
          }
      }
      
      fun Context.sendTaskerCommandNoExceptions(command: String) = try {
          sendTaskerCommand(command)
          true
      } catch (t: Throwable) {
          false
      }
   

Request permission from the user to send commands:

   
      requestPermissions(arrayOf(PERMISSION_SEND_COMMAND),1231)
   

And finally send the command you want:

   
      button.setOnClickListener { sendTaskerCommand("test") }
   

Check out a demo of this in action here: YouTube Demo