Hi,
I have a Flow which checks if my VPN is accessible and if not, then it starts the VPN. This works nicely. However, then the VPN is the foreground app.
I'd like my Flow to start VPN if needed, then swap back to the app that was in the foreground before the Flow started.
For example, I have Firefox open, the Flow runs, starts the VPN and then switches back to Firefox.
How to detect that foreground app?
Thanks!
Mark
Detect foreground app
Moderator: Martin
Re: Detect foreground app
Another (maybe easier option) - How can I minimize an app? Control-UI?
This way, I'd run the VPN app then minimize it and theoretically, I'd be back in the app I was before.
Thanks,
Mark
This way, I'd run the VPN app then minimize it and theoretically, I'd be back in the app I was before.
Thanks,
Mark
Re: Detect foreground app
Hi,
You can use 'Control UI' for this. Maybe even a single line with back(); can work, depending on the VPN app.
Regards,
Martin
You can use 'Control UI' for this. Maybe even a single line with back(); can work, depending on the VPN app.
Regards,
Martin
Re: Detect foreground app
OK, so this is not working so smoothly, so I'm back looking at alternatives.
I'd like the flow to:
1. Detect the current foreground app.
2. Do stuff (start VPN)
3. Switch back to the app detected in step 1.
I found a Github project https://github.com/ricvalerio/foregroundappchecker which provides code to detect the foregound app. Can this be done in Automagic? If not, maybe the devs can use this code and add that capability?
I'd like the flow to:
1. Detect the current foreground app.
2. Do stuff (start VPN)
3. Switch back to the app detected in step 1.
I found a Github project https://github.com/ricvalerio/foregroundappchecker which provides code to detect the foregound app. Can this be done in Automagic? If not, maybe the devs can use this code and add that capability?
Re: Detect foreground app
Foreground app detection can be done already using trigger App Task Started, either using classic (Control UI) or usage statistic. However this require you to save every app changes first before getting into the app. To detect current foreground app without storing previous value, currently we still need root to get the dumpsys result. Once we have AM 1.38 released, we can do it without root anymore.
But for your case, it is much easier to use control UI : back(), to get back to the previous foreground app before the VPN app.
But for your case, it is much easier to use control UI : back(), to get back to the previous foreground app before the VPN app.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Re: Detect foreground app
Thanks much for your response. The back() is imperfect just because of the VPN app. My phone is rooted. Is there a way with the current AM to get the current app (using root)?Desmanto wrote: ↑09 Dec 2019 17:55Foreground app detection can be done already using trigger App Task Started, either using classic (Control UI) or usage statistic. However this require you to save every app changes first before getting into the app. To detect current foreground app without storing previous value, currently we still need root to get the dumpsys result. Once we have AM 1.38 released, we can do it without root anymore.
But for your case, it is much easier to use control UI : back(), to get back to the previous foreground app before the VPN app.
Thanks again and look forward to 1.38
Re: Detect foreground app
I found this:
https://stackoverflow.com/questions/131 ... t-activity
This root command seems to work:
dumpsys activity recents | grep "Recent #0"
I'm working on chopping up the result to just get the app name now.
edit:
dumpsys activity recents | grep "Recent #0" | cut -f 3 -dA= | cut -f 1 -d' ' | tr -d "\n"
seems to get me the app name, at least in terminal where I am testing it. Next to incorporate into a flow!
https://stackoverflow.com/questions/131 ... t-activity
This root command seems to work:
dumpsys activity recents | grep "Recent #0"
I'm working on chopping up the result to just get the app name now.
edit:
dumpsys activity recents | grep "Recent #0" | cut -f 3 -dA= | cut -f 1 -d' ' | tr -d "\n"
seems to get me the app name, at least in terminal where I am testing it. Next to incorporate into a flow!
Last edited by markd89 on 11 Dec 2019 16:00, edited 1 time in total.
Re: Detect foreground app
Yeah, you got it. I was going to use the same method, but using regex instead of cut.
Execute root command
Then use regex to get the package name
Execute root command
Code: Select all
dumpsys activity recents | grep 'Recent #0'
Code: Select all
f = findAll(stdout, ' \\* Recent #0: TaskRecord\\{.* A=(.*) U=.*\\}', true);
pn = f[0][1];
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.