usagestatsmanager

Android 6.0 Marshmallow UsageStatsManager issue when trying to retrieve foreground app

纵饮孤独 提交于 2019-11-28 02:49:12
问题 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 notification. As a result, I get false alarms that the foreground application has changed. I can't seem to find a way to filter those specific draws. Any ideas? Right now, I query for the foreground app with the following code. The problem exists only

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

戏子无情 提交于 2019-11-27 11:57:47
问题 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 store apps are able to show the usage Statistics Break free App Usage 回答1: Apps with usage access settings Activity Classes :- package com.example.android.appusagestatistics; import android.app.Activity; import android.app.usage.UsageStats; import

How to get Usage Access Permission programmatically

匆匆过客 提交于 2019-11-27 03:29:12
问题 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 my working code public void showDialog() { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { @SuppressWarnings("WrongConstant") UsageStatsManager usm = (UsageStatsManager) getSystemService("usagestats"); long time =

How to check if “android.permission.PACKAGE_USAGE_STATS” permission is given?

对着背影说爱祢 提交于 2019-11-26 20:23:58
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: <uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" tools:ignore="ProtectedPermissions"/> opening the activity that will let the user confirm giving you this permission: startActivity(new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)); getting the stats, aggregated : private static final String USAGE_STATS_SERVICE ="usagestats"; // Context.USAGE_STATS_SERVICE); ... final UsageStatsManager usageStatsManager=

How to use UsageStatsManager?

微笑、不失礼 提交于 2019-11-26 11:10:36
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 impossible. The problem I've made a post about it ( here , and another, similar one created by someone else, here ) and requested to re-consider it, and Google decided to make a new class, that seem to provide a similar functionality (more like statistics, but might also be useful), but I can't find out how to use it. The class is called "