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

m
 
(25 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<pre style="background-color: #EEEEEE; color: Black; border-radius: 10px; padding: 10px;">
+
<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>
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'
+
''' Options '''
  
Accessibility can be granted by following the steps in the popup or by pressing the notification that appears from MacroDroid.
+
* '''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
  
Any other issues, please consult the Troubleshooting section under the left hamburger menu from the MacroDroid home screen.
+
''' Application Selection '''
</pre><br>
 
<pre style="background-color: #EEEEEE; color: Black; border-radius: 10px; padding: 10px;">
 
Supported configurations:
 
  
Force legacy mechanism:
+
After choosing the event type, you can specify which applications to monitor:
Try this option if you have issues with the new application launched trigger implementation, or don't want to enable Accessibility access for MacroDroid.
 
  
Prevent notifications interfering:
+
* '''Select Applications''' - Choose specific applications from a searchable list. Multiple apps can be selected.
Swiping down the status bar may interfere with this trigger. This option prevents this interference but may cause issues with the trigger on some devices.
+
* '''Enter Package Name''' - Manually enter a package name. Supports magic text for dynamic package names.
</pre><br>
+
* '''All Applications''' - Trigger fires for any application launch/close (excluding MacroDroid itself and system UI)
  
'''Example Usage:'''<br/>
+
When selecting specific applications, you can:
When starting YouTube the screen rotation will be activated
+
* Search for apps by name
<pre style="background-color: red; color: white; border-radius: 10px; padding: 10px;">
+
* Show non-launchable apps using the checkbox
Triggers
+
* Select multiple applications
 +
* Previously selected apps appear at the top of the list
  
Application launched (YouTube)
+
''' Settings '''
</pre><br>
 
<pre style="background-color: #1665B0; color: white; border-radius: 10px; padding: 10px;">
 
Actions
 
  
Enable screen rotation.
+
* '''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.
</pre><br>
+
* '''Prevent notification interrupt''' - Available when using legacy mode on certain Android versions
<pre style="background-color: green; color: white; border-radius: 10px; padding: 10px;">
 
Constrains
 
  
 +
''' Magic Text '''
  
</pre><br>
+
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.
'''Example Usage:'''<br/>
 
When closing YouTube the screen rotation will be deactivate
 
<pre style="background-color: red; color: white; border-radius: 10px; padding: 10px;">
 
Triggers
 
  
Application closed(YouTube)
+
The trigger also provides context information including the app name and package name that can be used in subsequent actions.
</pre><br>
 
<pre style="background-color: #1665B0; color: white; border-radius: 10px; padding: 10px;">
 
Actions
 
  
Disable screen rotation.
+
* {app_package}
</pre><br>
+
* {app_name}
<pre style="background-color: green; color: white; border-radius: 10px; padding: 10px;">
 
Constrains
 
  
 +
''' Examples '''
  
</pre><br>
+
''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