Any help or suggestions please....
On Tuesday, 8 September 2015 17:17:52 UTC+5:30, SGCB wrote:
>
> In my app, i have to get the app usage statistics including app name,
> total foreground duration and launch count. But i am not able to get
> mLaunchCount, have anyone know alternative way to get the value.
>
> Below is my code to get app name and foreground time:
>
> UsageStatsManager mUsageStatsManager =
> (UsageStatsManager)getSystemService(Context.USAGE_STATS_SERVICE);
> Calendar cal = Calendar.getInstance();
> cal.add(Calendar.YEAR, -1);
> List<UsageStats> queryUsageStats = mUsageStatsManager
> .queryUsageStats(UsageStatsManager.INTERVAL_DAILY,
> cal.getTimeInMillis(),
> System.currentTimeMillis());
> for(int i=0;i<queryUsageStats.size();i++){
> UsageStats data = queryUsageStats.get(i);
> PackageManager packageManager=
> getApplicationContext().getPackageManager();
> String appName;
> try {
> appName = (String)
> packageManager.getApplicationLabel(packageManager.getApplicationInfo(data.getPackageName(),
> PackageManager.GET_META_DATA));
> } catch (final PackageManager.NameNotFoundException e) {
> appName = "Unknown";
> }
> str = str.append(appName+"
> "+data.getTotalTimeInForeground()/1000+"s "+"\n");
> }
>
>
--
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
---
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.