The error you're encountering is related to Android's security model and how it handles display affinity and permissions when launching apps programmatically, especially in a multi-display or headless environment (like Termux or a secondary display).
Permission Denial: The system is blocking the intent because the calling process (Termux API) does not have the necessary permissions or context to launch the app on the specified display.launchDisplayId=27: The intent is trying to launch the app on a specific display (ID 27), which is likely not the primary display. Android restricts launching apps on non-primary displays unless explicitly allowed.When you launch the app manually (e.g., from the launcher), Android uses the primary display by default, and the system grants the necessary permissions implicitly. The Termux API, however, is trying to launch the app programmatically, and Android enforces stricter checks for security reasons.
Modify your intent to explicitly target the primary display (usually display ID 0). You can do this by setting the launchDisplayId to 0 or omitting it entirely, as the default is the primary display.
Example (in your Termux API code):
basham start -n im.vector.app/im.vector.application.features.Alias --display 0
Ensure the Termux API app has all the necessary permissions, especially:
android.permission.INTERACT_ACROSS_USERSandroid.permission.SYSTEM_ALERT_WINDOW (if applicable)android.permission.WRITE_SECURE_SETTINGS (rarely granted to non-system apps)However, some of these permissions are restricted and cannot be granted to regular apps (including Termux API) without root access or ADB commands.
If you have ADB access, you can try launching the app via ADB, which bypasses some of the restrictions:
bashadb shell am start -n im.vector.app/im.vector.application.features.Alias
Some apps (like Element) may not fully support being launched on secondary displays or in headless environments. If Element is not designed for this, it may fail regardless of permissions.
If Termux API is too restrictive, consider using automation apps like Tasker or MacroDroid, which can sometimes launch apps in specific contexts with more flexibility.
Verify Display IDs:
List all connected displays to confirm the ID of the primary display:
bashdumpsys display
Look for HDR10DisplayView or displayId=0 (usually the primary display).
Test with a Simpler App:
Try launching a basic app (e.g., com.android.calculator2) using the same method to isolate whether the issue is specific to Element or a general restriction.
Logcat Output:
Check logcat for more detailed errors:
bashlogcat | grep -i "Permission Denial"
If you're using the Termux API to launch the app, try this command:
bashtermux-open --view im.vector.app
or:
basham start -n im.vector.app/im.vector.application.features.Alias --display 0