by P. Andreas Schmidt, IVE
Version 3 (June 30, 2023)
Download (71 downloads)
No premium - no root - ADB for permissions (read here https://llamalab.com/automate/doc/adb.html)
Update:
1-added a fork so that it would stop checking when unlocked etc...
2-for Android 13: it will only work once/for a short time after you've given permission upon opening the block. So as a workaround (as stated in documentation) added block 74 with ADB shell (this means you need some adb (over wifi) working and have to configure the block first for that). So just swap the blocks and it should work just fine. The ADB is likely slower so it may be necessary to increase the difference between clicks in block 46 (read below). Also it may not work quite as well (not every time, for a double click anyway).
Since the other flows that use the key pressed blocks or monitor volume in/decrease to catch volume keys whilst screen locked don't work on my phone (LG Velvet, Android 12) I came up with this solution, hope it helps others.
It checks the main logs for volume key events. This concrete example checks for both, but only acts on a double press of the same within a half second. You can of course adapt to anything you need, single press, or first up then down, etc... It is also possible to catch pressing down or release.
Mainly you need to adapt blocks 43 & 46.
43 listens to main logs, so adapt regex to your needs.
46 checks both time between presses (0.5, so change that if needed) as well as if it's the same button pressed for the second time (so depending on what you need...). If you just want one press, you obviously don't need the moment variable and block 46.
You could also try to listen for other keys. When you want to find out be careful how you do! I just used output of all main log events to the AM flow's log. But then I had to reboot the phone to get AM to work again... Probably better to listen via PC.