usage_stats 패키지는 플러터 애플리케이션에서 앱 사용 시간, 구성 변경 및 사용자 상호작용 이벤트를 포함한 안드로이드 사용 통계를 쿼리할 수 있도록 합니다. 사용자가 장치와 설치된 앱과 어떻게 상호작용하는지에 대한 시스템 수준의 데이터에 접근할 수 있으며, 사용 패턴에 대한 통찰을 제공합니다. 이 패키지는 안드로이드 전용으로 설계되어 안드로이드 UsageStatsManager API를 활용합니다. 분석, 생산성 도구 또는 디지털 웰빙 애플리케이션과 같이 시간에 따라 앱 및 기기 사용을 세밀하게 추적해야 하는 경우에 유용합니다.
사용 사례
앱 사용 패턴 분석
디지털 웰빙 모니터링
사용자 행동 추적
장치 활동 보고
앱에서 보낸 시간
주요 기능
Android UsageStatsManager에 액세스
실시간 사용 이벤트 수집
구성 및 사용 데이터를 지원합니다
플랫폼 전용(안드로이드 전용)
가볍고 간단한 통합
적합한 대상
생산성 앱
웰빙 트래커
분석 도구
안드로이드 중심 앱
사용 기반 기능을 개발하는 개발자
고려 사항
Android 전용 플랫폼 지원
런타임 권한이 필요합니다
Android OS에 한정
데이터 접근을 위해 사용자 동의가 필요할 수 있습니다
시스템 수준의 Android API에 의존합니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
usage_stats
Query Android usage statistics from Flutter: app usage and events, configuration
changes, app standby buckets, on-device storage usage, and per-app network data.
The plugin wraps Android's UsageStatsManager, NetworkStatsManager,
StorageStatsManager, and PackageManager behind a single UsageStats facade.
This package is Android only. iOS does not expose comparable per-app usage
data to third-party apps, so the plugin declares no iOS implementation.
Screenshots
The bundled example app showcases every API:
Install
Add usage_stats to your pubspec.yaml:
dependencies:usage_stats:^2.0.0
Android setup
The plugin targets API level 23 (Android 6.0) as a minimum. Most queries need the
special PACKAGE_USAGE_STATS permission, which the user grants from system
settings rather than through a runtime dialog.
Add the permission to your android/app/src/main/AndroidManifest.xml, inside the
manifest element:
Send the user to the system "Usage access" screen and check whether access has
been granted:
import'package:usage_stats/usage_stats.dart';
// Opens the system Usage Access settings screen (only if not yet granted).awaitUsageStats.grantUsagePermission();
// Opens the same screen unconditionally, e.g. for a "Manage access" button.awaitUsageStats.openUsageAccessSettings();
// Returns true once the user has enabled access for your app.bool? granted = awaitUsageStats.checkUsagePermission();
queryUsageStats and queryEventStats accept an optional intervalType that
maps to UsageStatsManager.INTERVAL_*. It defaults to IntervalType.best.
final monthly = awaitUsageStats.queryUsageStats(
startDate,
endDate,
intervalType: IntervalType.monthly,
);
Network usage
// Per-app network usage for all apps.List<NetworkInfo> network = awaitUsageStats.queryNetworkUsageStats(
startDate,
endDate,
networkType: NetworkType.all, // or NetworkType.wifi / NetworkType.mobile
);
// Network usage for a single package.NetworkInfo info = awaitUsageStats.queryNetworkUsageStatsByPackage(
startDate,
endDate,
packageName: 'com.example.app',
);
Network totals are summed across the Wi-Fi and cellular transports. When a VPN
is active the platform may attribute traffic to the VPN app as well as the
originating app, which can make per-app totals appear higher than expected.
Storage usage
// App, data, and cache bytes for a package (Android 8 / API 26+).StorageInfo? storage = awaitUsageStats.queryStorageStats('com.example.app');
print(storage?.totalBytes);
Querying your own package needs no permission; querying other packages requires
PACKAGE_USAGE_STATS.
App metadata and icons
// Label, system flag, version, and install times for one package.AppInfo? app = awaitUsageStats.getAppInfo('com.example.app');
// Every installed app the caller can see (set includeSystem: false to skip// system apps).List<AppInfo> installed =
awaitUsageStats.queryInstalledApps(includeSystem: false);
// PNG launcher icon bytes.Uint8List? icon = awaitUsageStats.getAppIcon('com.example.app');
On Android 11+ (API 30) package-visibility rules apply. Without a <queries>
entry in your manifest, queryInstalledApps returns only visible packages. The
plugin deliberately does not request QUERY_ALL_PACKAGES, since it is a
Play-policy sensitive permission.
App standby
// This app's standby bucket (no permission required, Android 9 / API 28+).int? bucket = awaitUsageStats.getAppStandbyBucket();
// Whether a package is currently idle (Android 6 / API 23+).bool? idle = awaitUsageStats.isAppInactive('com.example.app');
// This app's own events without the usage-access prompt (Android 9 / API 28+).List<EventUsageInfo> ownEvents =
awaitUsageStats.queryEventsForSelf(startDate, endDate);
Typed accessors
For backwards compatibility the model fields are returned as strings, mirroring
the raw platform values. Every model also exposes typed getters so you do not
have to parse them yourself:
final info = usage.first;
info.totalTimeInForegroundMs; // int? (milliseconds)
info.lastTimeUsedDate; // DateTime?
events.first.eventTypeDescription; // e.g. 'ACTIVITY_RESUMED'
network.first.rxTotalBytesValue; // int?
totalTimeInForeground is reported in milliseconds.