Checking if app is running

Post your questions and help other users.

Moderator: Martin

Post Reply
aximili
Posts: 14
Joined: 28 Jun 2018 11:14

Checking if app is running

Post by aximili » 01 Sep 2018 07:11

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)

User avatar
Desmanto
Posts: 1945
Joined: 21 Jul 2017 17:50

Re: Checking if app is running

Post by Desmanto » 02 Sep 2018 17:09

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

Code: Select all

ps -A | grep packagenameoftheapp
If it return null or nothing, you know the app is not running. But if it returns some lines, then the app is running.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), Resurrection Remix Official 7.0.2 20190714, Pie 9.0, Rooted.

aximili
Posts: 14
Joined: 28 Jun 2018 11:14

Re: Checking if app is running

Post by aximili » 03 Sep 2018 10:07

Thanks Desmanto.

I do have root, but running this command

Code: Select all

ps -A | grep a
returns:
exit_code = 1
stderr = ps: -
stdout =

Did I miss anything?

User avatar
Desmanto
Posts: 1945
Joined: 21 Jul 2017 17:50

Re: Checking if app is running

Post by Desmanto » 03 Sep 2018 18:00

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.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), Resurrection Remix Official 7.0.2 20190714, Pie 9.0, Rooted.

aximili
Posts: 14
Joined: 28 Jun 2018 11:14

Re: Checking if app is running

Post by aximili » 09 Oct 2018 07:52

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?

User avatar
Desmanto
Posts: 1945
Joined: 21 Jul 2017 17:50

Re: Checking if app is running

Post by Desmanto » 09 Oct 2018 11:38

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.

Code: Select all

ps -A | grep com.mixplorer
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

Code: Select all

isEmpty(stdout)
or

Code: Select all

stdout == ''
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

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), Resurrection Remix Official 7.0.2 20190714, Pie 9.0, Rooted.

aximili
Posts: 14
Joined: 28 Jun 2018 11:14

Re: Checking if app is running

Post by aximili » 03 Nov 2018 00:40

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)

Post Reply