> Let me clarify you about my requirement. > I actually want to monitor all the apps stored in the device, and retrieve > their information (like how many times app is opened or closed. All that > process of maintaining the record will start, when I first time install my > app (which will show me details of other apps). > > For this reason, I wanted that as soon as any device app (system's app as > well as user's apps), is launched or closed, the database should be updated > like --- > *App A started: 2 times and stopped 1 time total usage: 15 hrs, App B > started 3 times stopped: 3 times, total usage: 7 hrs* > > And in my own application, I can retrieve that information. > > I wish, my problem is somewhat clear to you. > > You almost just want to grab the output of "dumpsys usagestats" but that's restricted to apps with the android.system.DUMP permission installed in /system/app. (I'm guessing that this level of data collection is not "evil" as Google has the DUMP permission in their proprietary Google Services Framework and Google Account Manager, but I'm not sure why it's discouraged for app developers but ok for google..) I think the DUMP permission changes between Dangerous and SystemOrSignature depending on what Android version you are looking at so you might have to be pre-installed on the device to do it (root/build your own ROM.)
If you don't want to poll, you could try a blocking read on "logcat -s -v time ActivityManager" and parse for the start intents (but you'd still have to go look for application exit in the RunningAppInfo, but you could only do that on ActivityManager messages so you'd only be doing it when the ActivityManager is changing applications.) You'd need the android.permission.READ_LOGS permission to do that. Neither of these are SDK supported, and both cost you an extra process, but the logcat process is pretty light weight, and the dumpsys would only need to be run once at reporting time. In theory the user would is alerted on application installation that you are requesting the dangerous permissions, so you might want to be clear about why you need them in your application description. In practice the de -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

