Reputation: 31
I am trying to make an app which will calculate the amount of time a third party app is used and after closing that it will pop up and display the amount of time the app was on. We can find the the same thing for our app usage by timestamp as described here: how to calculate time spent on my app by timestamp
How can I calculate the (on/activated)time of third party app?
Upvotes: 3
Views: 70
Reputation: 1502
I guess you call a third party app from an activity so you could either calculate the delay starting when the app is called for result and ending when onActivityResult is called.
You could also start the timer when onPause is called and end it when onResume is called, because your activity loses focus when another starts.
EDIT
If your app is not launching other apps, then you can use a service with the READ_LOGS permission and detect the ActivityManager logs to see which intents were called, something like
I/ActivityManager( 585): Starting activity: Intent { action=android.intent.action,..}
Search for the ActivityManager tag.
Upvotes: 2