Difference between revisions of "Trigger: Application Launched/Closed"

(Created page with "This trigger fires when an application is launched or closed. There are also two methods, due to recent changes to Android, there is a faster method with the use of accessibil...")
 
 
(37 intermediate revisions by 3 users not shown)
Line 1: Line 1:
This trigger fires when an application is launched or closed. There are also two methods, due to recent changes to Android, there is a faster method with the use of accessibility services, however it is still possible to avoid accessibility services by ticking the box 'force legacy system'
+
<pre class="header-style">The Application Launched/Closed trigger fires when an application becomes the foreground application (launched) or when it is no longer the foreground app (closed). This is useful for automating actions based on which app is currently in use.</pre>
  
Accessibility can be granted by following the steps in the popup or by pressing the notification that appears from MacroDroid.
+
''' Options '''
  
Any other issues, please consult the Troubleshooting section under the left hamburger menu from the MacroDroid home screen.
+
* '''Application Launched''' - Trigger fires when the selected application becomes the foreground app
 +
* '''Application Closed''' - Trigger fires when the selected application is no longer the foreground app
 +
 
 +
''' Application Selection '''
 +
 
 +
After choosing the event type, you can specify which applications to monitor:
 +
 
 +
* '''Select Applications''' - Choose specific applications from a searchable list. Multiple apps can be selected.
 +
* '''Enter Package Name''' - Manually enter a package name. Supports magic text for dynamic package names.
 +
* '''All Applications''' - Trigger fires for any application launch/close (excluding MacroDroid itself and system UI)
 +
 
 +
When selecting specific applications, you can:
 +
* Search for apps by name
 +
* Show non-launchable apps using the checkbox
 +
* Select multiple applications
 +
* Previously selected apps appear at the top of the list
 +
 
 +
''' Settings '''
 +
 
 +
* '''Force legacy mode''' - Uses an older polling-based method instead of the Accessibility Service. This may be needed on some devices but is less efficient. When enabled, additional settings become available for API 21/22 compatibility.
 +
* '''Prevent notification interrupt''' - Available when using legacy mode on certain Android versions
 +
 
 +
''' Magic Text '''
 +
 
 +
When using the "Enter Package Name" option, you can use magic text to specify the package name dynamically. This allows for variable-based app detection.
 +
 
 +
The trigger also provides context information including the app name and package name that can be used in subsequent actions.
 +
 
 +
* {app_package}
 +
* {app_name}
 +
 
 +
''' Examples '''
 +
 
 +
''Example 1: Mute When Opening Video App''
 +
  <pre class="trigger-style">Triggers
 +
 
 +
Application Launched (YouTube)</pre>
 +
  <pre class="action-style">Actions
 +
 
 +
Volume Change: Media Volume to 0</pre>
 +
 
 +
''Example 2: Lock Screen When Leaving Banking App''
 +
  <pre class="trigger-style">Triggers
 +
 
 +
Application Closed (Banking App)</pre>
 +
  <pre class="action-style">Actions
 +
 
 +
Screen Lock</pre>
 +
 
 +
''' Notes '''
 +
 
 +
* By default, this trigger uses the Accessibility Service to detect foreground app changes, which is efficient and reliable
 +
* The legacy polling mode requires Usage Access permission on Android 5.1 (API 22) and above
 +
* When "Application Closed" macros are triggered, they are processed before "Application Launched" macros for the new foreground app
 +
* The trigger ignores soft input windows (keyboards) to avoid false triggers when the keyboard appears
 +
 
 +
''' Permissions Required '''
 +
 
 +
* '''Accessibility Service''' - Required for the default (non-legacy) mode
 +
* '''Usage Access''' - Required for legacy mode on Android 5.1+
 +
 
 +
''' See Also '''
 +
 
 +
* [[Constraint:_Application_Running|Application Running Constraint]]

Latest revision as of 21:27, 5 January 2026

The Application Launched/Closed trigger fires when an application becomes the foreground application (launched) or when it is no longer the foreground app (closed). This is useful for automating actions based on which app is currently in use.

Options

  • Application Launched - Trigger fires when the selected application becomes the foreground app
  • Application Closed - Trigger fires when the selected application is no longer the foreground app

Application Selection

After choosing the event type, you can specify which applications to monitor:

  • Select Applications - Choose specific applications from a searchable list. Multiple apps can be selected.
  • Enter Package Name - Manually enter a package name. Supports magic text for dynamic package names.
  • All Applications - Trigger fires for any application launch/close (excluding MacroDroid itself and system UI)

When selecting specific applications, you can:

  • Search for apps by name
  • Show non-launchable apps using the checkbox
  • Select multiple applications
  • Previously selected apps appear at the top of the list

Settings

  • Force legacy mode - Uses an older polling-based method instead of the Accessibility Service. This may be needed on some devices but is less efficient. When enabled, additional settings become available for API 21/22 compatibility.
  • Prevent notification interrupt - Available when using legacy mode on certain Android versions

Magic Text

When using the "Enter Package Name" option, you can use magic text to specify the package name dynamically. This allows for variable-based app detection.

The trigger also provides context information including the app name and package name that can be used in subsequent actions.

  • {app_package}
  • {app_name}

Examples

Example 1: Mute When Opening Video App

Triggers

Application Launched (YouTube)
Actions

Volume Change: Media Volume to 0

Example 2: Lock Screen When Leaving Banking App

Triggers

Application Closed (Banking App)
Actions

Screen Lock

Notes

  • By default, this trigger uses the Accessibility Service to detect foreground app changes, which is efficient and reliable
  • The legacy polling mode requires Usage Access permission on Android 5.1 (API 22) and above
  • When "Application Closed" macros are triggered, they are processed before "Application Launched" macros for the new foreground app
  • The trigger ignores soft input windows (keyboards) to avoid false triggers when the keyboard appears

Permissions Required

  • Accessibility Service - Required for the default (non-legacy) mode
  • Usage Access - Required for legacy mode on Android 5.1+

See Also