usagestatsmanager

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

六月ゝ 毕业季﹏ 提交于 2019-12-17 05:03:10
问题 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

How to use UsageStatsManager?

こ雲淡風輕ζ 提交于 2019-12-17 02:07:09
问题 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,

App not listed in “Apps with usage access” activity

一曲冷凌霜 提交于 2019-12-10 17:27:11
问题 I'm writing an android app for marshmallow (sdk 23) with Android Studio, which creates some charts/diagrams by retrieving the past network activities with the NetworkStatsManager-class. Therefore I added the necessary permission in the manifest: <uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" tools:ignore="ProtectedPermissions" /> The "Apps with usage access" is opened automatically with an intent, so the user can permit the needed access. The problem is: My app is not

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

◇◆丶佛笑我妖孽 提交于 2019-12-06 04:11:34
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 = (UsageStatsManager)this.getSystemService(Context.USAGE_STATS_SERVICE); long time = System.currentTimeMillis(); List<UsageStats> appList = usm.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, time - 10000*10000, time); if (appList != null && appList.size() == 0) { Log.d("Executed app", "######### NO APP FOUND ##########" ); } if (appList != null && appList.size() > 0) { SortedMap<Long, UsageStats

Android get UsageStatsManager in API level 21

情到浓时终转凉″ 提交于 2019-12-06 02:46:10
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! Context.getSystemService(UsageStatsService) was added only in API level 22! The question is - how to get needed data in API 21 ?? According dashboards , there is 13% of users at this API level, I don't wanna lose them. Well Context#getSystemService(...) was introduced in API level 1 but Contexts' USAGE_STATS_SERVICE String was introduced in API

Android: UsageStatsManager not returning correct daily results

瘦欲@ 提交于 2019-12-03 13:54:29
问题 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<UsageStats> getUsageStatsList(Context context){ UsageStatsManager usm = getUsageStatsManager(context); Calendar calendar = Calendar.getInstance(); long endTime = calendar.getTimeInMillis(); calendar.add(Calendar.DAY_OF_YEAR, -1); long startTime = calendar.getTimeInMillis(); List<UsageStats> usageStatsList = usm

Android: UsageStatsManager not returning correct daily results

♀尐吖头ヾ 提交于 2019-12-03 03:12:02
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<UsageStats> getUsageStatsList(Context context){ UsageStatsManager usm = getUsageStatsManager(context); Calendar calendar = Calendar.getInstance(); long endTime = calendar.getTimeInMillis(); calendar.add(Calendar.DAY_OF_YEAR, -1); long startTime = calendar.getTimeInMillis(); List<UsageStats> usageStatsList = usm.queryUsageStats(UsageStatsManager.INTERVAL_DAILY,startTime, endTime); return usageStatsList; } I have an alarm that

Android UsageStatsManager producing wrong output?

99封情书 提交于 2019-12-01 05:22:19
问题 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 DAILY intervals. With WEEKLY , my code and output is given below; Code: Calendar beginCal = Calendar.getInstance(); beginCal.set(Calendar.DATE, 1); beginCal.set(Calendar.MONTH, 0); beginCal.set(Calendar.YEAR, 2012); Calendar endCall = Calendar

Android P: UsageStatsManager getAppStandbyBucket

笑着哭i 提交于 2019-11-29 18:10:05
I want to display the current bucket of my application with a device under Android P beta. Therefore, I try to use the UsageStatsManager class like this : @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (Build.VERSION.SDK_INT >= 28) { UsageStatsManager usageStatsManager = (UsageStatsManager) getSystemService(USAGE_STATS_SERVICE); if (usageStatsManager != null) { Log.d(TAG, "getAppStandbyBucket():" + usageStatsManager.getAppStandbyBucket()); } } } My Manifest possesses the permission android.permission

Android 6.0 Marshmallow UsageStatsManager issue when trying to retrieve foreground app

百般思念 提交于 2019-11-29 09:08:58
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 in Marshmallow (5.X works correctly). UsageStatsManager mUsageStatsManager = (UsageStatsManager)