{"id":20082410,"url":"https://github.com/googlesamples/android-appusagestatistics","last_synced_at":"2025-04-06T07:14:22.425Z","repository":{"id":24643656,"uuid":"28053192","full_name":"googlesamples/android-AppUsageStatistics","owner":"googlesamples","description":null,"archived":false,"fork":false,"pushed_at":"2021-06-23T08:09:08.000Z","size":808,"stargazers_count":373,"open_issues_count":14,"forks_count":114,"subscribers_count":45,"default_branch":"master","last_synced_at":"2025-03-30T06:08:21.641Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/googlesamples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-12-15T19:49:51.000Z","updated_at":"2025-03-14T11:57:59.000Z","dependencies_parsed_at":"2022-08-23T04:31:39.217Z","dependency_job_id":null,"html_url":"https://github.com/googlesamples/android-AppUsageStatistics","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/googlesamples%2Fandroid-AppUsageStatistics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/googlesamples%2Fandroid-AppUsageStatistics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/googlesamples%2Fandroid-AppUsageStatistics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/googlesamples%2Fandroid-AppUsageStatistics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/googlesamples","download_url":"https://codeload.github.com/googlesamples/android-AppUsageStatistics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247445681,"owners_count":20939961,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T15:43:16.957Z","updated_at":"2025-04-06T07:14:22.387Z","avatar_url":"https://github.com/googlesamples.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"\nAndroid AppUsageStatistics Sample\n===================================\n\nA basic app showing how to use App usage statistics API to let users collect statistics related\nto usage of the applications.\n\nIntroduction\n------------\n\nThe [App usage statistics][1] API allows app developers to collect statistics related to usage of\nthe applications. This API provides more detailed usage information than the deprecated\n[getRecentTasks()][2] method.\n\nThis example illustrates how to use the App usage statistics API by showing the applications sorted\nby the timestamp of the last time each app was used.\n\nTo use this API, you must first declare the `android.permission.PACKAGE_USAGE_STATS` permission\nin your manifest. The user must also enable access for this app through\n`Settings \u003e Security \u003e Apps with usage access`.\n\nTo collect the statistics of the app usage, you need to first get the instance of\n[UsageStatsManager][3] by the following code:\n\n```java\nmUsageStatsManager = (UsageStatsManager) getActivity()\n       .getSystemService(Context.USAGE_STATS_SERVICE);\n```\n\nThen you can retrieve the statistics of the app usage by the following method:\n\n```java\nCalendar cal = Calendar.getInstance();\ncal.add(Calendar.YEAR, -1);\nList\u003cUsageStats\u003e queryUsageStats = mUsageStatsManager\n        .queryUsageStats(UsageStatsManager.INTERVAL_DAILY, cal.getTimeInMillis(),\n                System.currentTimeMillis());\n```\n\nThe first argument of the [queryUsageStats()][4] is used for the time interval by which the\nstats are aggregated. The second and the third arguments are used for specifying the beginning\nand the end of the range of the stats to include in the results.\n\n[1]: https://developer.android.com/reference/android/app/usage/package-summary.html\n[2]: https://developer.android.com/reference/android/app/ActivityManager.html#getRecentTasks(int%2C%20int)\n[3]: https://developer.android.com/reference/android/app/usage/UsageStatsManager.html\n[4]: https://developer.android.com/reference/android/app/usage/UsageStatsManager.html#queryUsageStats(int%2C%20long%2C%20long)\n\nPre-requisites\n--------------\n\n- Android SDK 27\n- Android Build Tools v27.0.2\n- Android Support Repository\n\nScreenshots\n-------------\n\n\u003cimg src=\"screenshots/screenshot-1.png\" height=\"400\" alt=\"Screenshot\"/\u003e \u003cimg src=\"screenshots/screenshot-2.png\" height=\"400\" alt=\"Screenshot\"/\u003e \n\nGetting Started\n---------------\n\nThis sample uses the Gradle build system. To build this project, use the\n\"gradlew build\" command or use \"Import Project\" in Android Studio.\n\nSupport\n-------\n\n- Google+ Community: https://plus.google.com/communities/105153134372062985968\n- Stack Overflow: http://stackoverflow.com/questions/tagged/android\n\nIf you've found an error in this sample, please file an issue:\nhttps://github.com/googlesamples/android-AppUsageStatistics\n\nPatches are encouraged, and may be submitted by forking this project and\nsubmitting a pull request through GitHub. Please see CONTRIBUTING.md for more details.\n\nLicense\n-------\n\nCopyright 2017 The Android Open Source Project, Inc.\n\nLicensed to the Apache Software Foundation (ASF) under one or more contributor\nlicense agreements.  See the NOTICE file distributed with this work for\nadditional information regarding copyright ownership.  The ASF licenses this\nfile to you under the Apache License, Version 2.0 (the \"License\"); you may not\nuse this file except in compliance with the License.  You may obtain a copy of\nthe License at\n\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\nWARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the\nLicense for the specific language governing permissions and limitations under\nthe License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgooglesamples%2Fandroid-appusagestatistics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgooglesamples%2Fandroid-appusagestatistics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgooglesamples%2Fandroid-appusagestatistics/lists"}