Detect other apps being launched and closed by external Service in Android
Asked Answered
H

0

2

I am currently trying to monitor applications being launched and closed under Android. I need to create Android Service app that accumulate statistics (Time, AppName) about starting and terminating selected apps.

I clear understand Processes and Application Lifecycle https://developer.android.com/guide/components/activities/process-lifecycle.html

And I know how to detect running app How can I check if an app running on Android?

Anyway are there any Android events to sucbscribe to listen for it?

Is it possible to do at least for MainActivity of the app?

Should monitored app have implemented some kind of interprocess Broadcast Messenger?

Thank you!

Helotry answered 9/2, 2018 at 5:46 Comment(11)
you can start a service at onStop() preferably at onPause() of your main activity to detect if your application was being closed or not. keeping in mind that your main activity will always be running throughout your application and will only be destroyed when your application stops.Patriotism
@Patriotism I mean. I want to create some independed Service that scans App1, App2 and App3. I assume should be system events to detect fact of starting and termination of Andoid app. Are there any those events?Helotry
you want to detect about your app or the other applications ? I believe we can detect about our app but need root or special permissions about other apps.Patriotism
And yes you can use either some broadcast reciver or call any other service to check when your app started or finished.Patriotism
@Patriotism I am currently trying to monitor other applications being launched and closed.Helotry
As far as I know you can't do that without root privileges, but let's see if someone finds a solution to this.Patriotism
You can try using UsageStatsManagerFuqua
@sshp From that page: "This API requires the permission android.permission.PACKAGE_USAGE_STATS, which is a system-level permission and will not be granted to third-party apps"Higa
@Higa Hi! I am intrested to detect launched and closed app EVENTS if they exist.Helotry
@Fuqua Well... It is not whant I am asking for exactly. I am intrested to detect launched and closed app EVENTS if they exist.Helotry
Refer to this answer. You have to do some extra work if you want to know which app is launched instantly.Fuqua

© 2022 - 2024 — McMap. All rights reserved.