I am trying to check if an app is running (so that I can re-launch it if it's been killed).
I am on Android 8.1.0
I have tried App Task Running and App Process Running, but they always return false even if the app (Display Brightness) is running in background.
What am I missing?
(On Tasker I used to use a plugin to do this, may be this one if I remembered correctly)
Checking if app is running
Moderator: Martin
Re: Checking if app is running
It's gone, Oreo totally prohibit app from querying other apps' processes. You need root to do that. If you have root already, you can use execute root command
If it return null or nothing, you know the app is not running. But if it returns some lines, then the app is running.
Code: Select all
ps -A | grep packagenameoftheapp
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: Checking if app is running
Thanks Desmanto.
I do have root, but running this command
returns:
exit_code = 1
stderr = ps: -
stdout =
Did I miss anything?
I do have root, but running this command
Code: Select all
ps -A | grep a
exit_code = 1
stderr = ps: -
stdout =
Did I miss anything?
Re: Checking if app is running
Do you have busybox installed? I have magisk busybox module installed. Probably you should use ps only. (without -A)
See : viewtopic.php?f=5&t=7533 for similar case. There is more detail about using the oom_adj to check whether the app is foreground or background.
You can try the command in terminal emulator with root access to see the output first, before trying it in Automagic.
See : viewtopic.php?f=5&t=7533 for similar case. There is more detail about using the oom_adj to check whether the app is foreground or background.
You can try the command in terminal emulator with root access to see the output first, before trying it in Automagic.
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: Checking if app is running
Hi Desmanto, thanks a lot for your reply.
I could use ps only (without -a without grep), but the result is huge, I'm not sure how to search for the Display Brightness.
Or do I have to install busybox? If so, which one? (In Magisk - Downloads, I could see "Busybox for Android NDK" and "busybox-ndk-nolinks")
pgrep works (for another app). Thanks for the link! But, how can I find out what the... (package name? the com.xxx...) for Display Brightness is?
I could use ps only (without -a without grep), but the result is huge, I'm not sure how to search for the Display Brightness.
Or do I have to install busybox? If so, which one? (In Magisk - Downloads, I could see "Busybox for Android NDK" and "busybox-ndk-nolinks")
pgrep works (for another app). Thanks for the link! But, how can I find out what the... (package name? the com.xxx...) for Display Brightness is?
Re: Checking if app is running
Just install the magisk module - Busybox for Android NDK. You can use the it for other purpose later.
To get the package name of the app, you can use MiXplorer from xda, at the app manager, you can see the packagename. You can copy the whole metadata of the app or even apk before installing it.
But we have Automagic. The easiest method is to go the trigger, choose trigger app task started/ended, choose the app and you got the packagename directly. Simply copy-paste it to the Execute root command.
Regardless using busybox or not, you can simply pipe the command to the grep, so it only output the lines you grep. For example we want to check if the mixplorer is running, MiXplorer is com.mixplorer or com.mixplorer.test if you use the testing version.
put condition debug dialog after the command to check the result. If mixplorer is running, you should see {stdout} has the result. If it is not, stdout will be empty or '' (two single quotes, nothing, but not null). Use expression
or
to check it. If true, app is not running. False, app is running. But it is a bit tricky though for some app that has service. Some might have the app running, but the service has different naming. You have to spot it then. You can find the different naming for the app at the condition service running.
For your case, Display Brightness Pro is rubberbigpepper.DisplayBrightnessPro (check with your version, I check it on xda version apk). The command become
To get the package name of the app, you can use MiXplorer from xda, at the app manager, you can see the packagename. You can copy the whole metadata of the app or even apk before installing it.
But we have Automagic. The easiest method is to go the trigger, choose trigger app task started/ended, choose the app and you got the packagename directly. Simply copy-paste it to the Execute root command.
Regardless using busybox or not, you can simply pipe the command to the grep, so it only output the lines you grep. For example we want to check if the mixplorer is running, MiXplorer is com.mixplorer or com.mixplorer.test if you use the testing version.
Code: Select all
ps -A | grep com.mixplorer
Code: Select all
isEmpty(stdout)
Code: Select all
stdout == ''
For your case, Display Brightness Pro is rubberbigpepper.DisplayBrightnessPro (check with your version, I check it on xda version apk). The command become
Code: Select all
ps -A | grep rubberbigpepper.DisplayBrightnessPro
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: Checking if app is running
This is perfect Desmanto thanks a lot for your help!
(I don't know why I couldn't get it working until now. I might have used the wrong pipe character)
(I don't know why I couldn't get it working until now. I might have used the wrong pipe character)