Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Track App Usage in Android? How to detect when an activity is launched?

Tags:

I need to track app usage in Android like how AppUsage does it (i.e. track number of app launches, and time spent using each). What I plan on doing is record the start time when an app is launched, and then get the end time when an app is paused or stopped. In LogCat, I'm able to see logs of Activity starting. I've looked at the available system broadcasts, I'm not sure if there is anything that broadcasts whenever an activity is started. . Basically, how do I detect when an activity is launched?

Edit: Moreover, Android also has a usage statistics system available internally which can be found in the Spare Parts app or when *#*#4636#*#* is dialed (Testing -> Usage statistics)

like image 815
sofiaguyang Avatar asked Jan 26 '12 00:01

sofiaguyang


People also ask

How do I find app history on Android?

On your Android phone, open the Google Play store app and tap the menu button (three lines). In the menu, tap My apps & games to see a list of apps currently installed on your device. Tap All to see a list of all apps you've downloaded on any device using your Google account.


2 Answers

We can now access app usage history on an Android device with the new android.app.usage API released as part of Android 5.0 APIs.The system collects the usage data on a per-app basis, aggregating the data over daily, weekly, monthly, and yearly intervals

For each app, the system records the following data:

  • The last time the app was used
  • The total length of time the app was in the foreground for that time interval (by day, week, month, or year)
  • Timestamp capturing when a component (identified by a package and activity name) moved to the foreground or background during a day

  • Timestamp capturing when a device configuration changed (such as when the device orientation changed because of rotation)

Refr : http://developer.android.com/reference/android/app/usage/package-summary.html

like image 147
android.fryo Avatar answered Oct 25 '22 08:10

android.fryo


Basically, how do I detect when an activity is launched?

You don't. There is nothing in the Android SDK for "the start time when an app is launched" nor "the end time when an app is paused or stopped".

What the app you cite is probably doing is wasting a lot of CPU time, RAM, and battery life, polling ActivityManager continuously.

Bear in mind that what you propose to track, if you plan on having anyone other than the user access it, borders on privacy violations of the type that got CarrierIQ in a fair amount of trouble.

like image 40
CommonsWare Avatar answered Oct 25 '22 06:10

CommonsWare