Questions tagged [usagestatsmanager]

UsageStatsManager provides access to Android device usage history and statistics. This tag is to be used with Android tag.

UsageStatsManager provides access to device usage history and statistics. Usage data is aggregated into time intervals: days, weeks, months, and years. 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. However, declaring the permission implies intention to use the API and the user of the device can grant permission through the Settings application.

This tag is to be used with tag.

92 questions
63
votes
7 answers

How to use UsageStatsManager?

Background Google has deprecated the function "getRecentTasks" of "ActivityManager" class. Now all it does is to get the list of apps that the current app has opened. I've even written a post about it here on StackOverflow, but I noticed it's…
46
votes
4 answers

How to check if "android.permission.PACKAGE_USAGE_STATS" permission is given?

Background I'm trying to get app-launched statistics, and on Lollipop it's possible by using the UsageStatsManager class, as such (original post here): manifest:
22
votes
3 answers

Android 6.0 Marshmallow UsageStatsManager issue when trying to retrieve foreground app

whenever I try to query the Usage Stats of the UsageStatsManager I can correctly get the last running app. However, if I pull down the status bar and there is a new notification, the last used app (based on UsageStats) will change to that of the…
fcdimitr
  • 528
  • 3
  • 16
21
votes
5 answers

Android: UsageStatsManager not returning correct daily results

I'm attempting to query UsageStats from UsageStatsManager, with the aim of returning all app packages that were used daily and for how long. The Code: public static List getUsageStatsList(Context context){ UsageStatsManager usm =…
21
votes
3 answers

How to Get the Time spent on an application in Android Programmatically

I want to get the Usage time of all those applications which i have used today. As i am getting the those details by dialing *#*#4636#*#*. But i want these details programmatically in android. please help me out in this. we can see how these play…
Himanshu Mori
  • 873
  • 1
  • 10
  • 20
15
votes
1 answer

How to get Usage Access Permission programmatically

My app needs to have Usage Access Permission in order to get information about the current running app on user's phone. I am able to successfully implement it using the following code with the help from the following link. Usage Access apps Here is…
Vivek Mishra
  • 5,669
  • 9
  • 46
  • 84
10
votes
1 answer

How to count app usage time while app is on foreground?

I'm working on an android app for tracking daily app usage. The idea is that a user can set daily time limit for any app and a notification will appear within at most 2 minutes after the limit is exceeded. (The reason for delay: I've created an…
Tanjim Ahmed Khan
  • 650
  • 1
  • 9
  • 21
10
votes
0 answers

Getting foreground app's packageName in Marshmallow delayed by 3 seconds

In Android 6.0 Marshmallow I query for the foreground app with the following code but there was a problem with incoming notifications because it shows foreground app to the app which sends notification. The problem exists only in Marshmallow (5.X…
9
votes
2 answers

queryUsageStats interval duration

I'm using UsageStatsManager API to get usage statistics for a certain time interval. All works fine if I use the predefined intervals i.e. INTERVAL_DAILY, INTERVAL_WEEKLY, INTERVAL_MONTHLY, INTERVAL_YEARLY. But if I want to view the data for the…
gaurav jain
  • 3,119
  • 3
  • 31
  • 48
8
votes
0 answers

Android API UsageStats getLastTimeUsed not correct?

I am trying to read when an app was last used using UsageStatsManager Class recently introduced in Android. But there is a issue. it gives proper result for most of apps. but for some apps for call :…
sunil
  • 177
  • 2
  • 12
7
votes
2 answers

Permission required to use UsageStatsManager

I'm trying to use UsageStatsManager. I understand that I need to put the following into my Android manifest: However, Eclipse…
7
votes
2 answers

Android UsageStatsManager producing wrong output?

I am using this link to produce app usage states. My understanding with chosen interval is that for YEARLY interval, it aggregates data for each YEAR for each package between beginTime and endTime duration. Similarly, it should work for WEEKLY and…
Max Testing
  • 135
  • 2
  • 8
6
votes
1 answer

Android get UsageStatsManager in API level 21

I need to get info about recent apps usage. Before API 21 it was used getRunningTasks or getRecentTasks to get this info. These methods were deprecated in API 21 according docs. There is UsageStatsManager class now, introduced in API level 21. But!…
5
votes
2 answers

How to get usage stats for "current day" using usageStatsManager in android (kotlin)

Objective: Need to get the usage stats for today (total time for which the device was used today) ie. 12.00 am to current time. Problem: 1.I get today's time + some other non explainable time 2.Non explainable time stamps(start and end of the usage…
itsam
  • 301
  • 2
  • 10
5
votes
1 answer

Android UsageStatsManager: Get a list of currently running apps on phone

I am trying to get a list of currently running apps on my phone. Here is the code I am using: if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { UsageStatsManager usm =…
anon_945500
  • 269
  • 3
  • 12
1
2 3 4 5 6 7