usage_stats 1.2.0 copy "usage_stats: ^1.2.0" to clipboard
usage_stats: ^1.2.0 copied to clipboard

PlatformAndroid

Query Android Usage Statistics (Configurations, Events, Usage)

usage_stats #

pub package pub points popularity likes

Query Android Usage Statistics (Configuration, Events, App Usage)

Install #

Add usage_stats as a dependency in pubspec.yaml.

Android #

Requires API level 22 as a minimum!

Add the following permission to the manifest namespace in AndroidManifest.xml:

    <uses-permission
        android:name="android.permission.PACKAGE_USAGE_STATS"
        tools:ignore="ProtectedPermissions" />

Usage #

import 'package:usage_stats/usage_stats.dart';

getUsage() async {

    DateTime endDate = new DateTime.now();
    DateTime startDate = DateTime(endDate.year, endDate.month, endDate.day, 0, 0, 0);
    
    // grant usage permission - opens Usage Settings
    UsageStats.grantUsagePermission();
    
    // check if permission is granted
    bool isPermission = UsageStats.checkUsagePermission();
    
    // query events
    List<EventUsageInfo> events = await UsageStats.queryEvents(startDate, endDate);
    
    // query usage stats
    List<UsageInfo> usageStats = await UsageStats.queryUsageStats(startDate, endDate);
    
    // query eventStats API Level 28
    List<EventInfo> eventStats = await UsageStats.queryEventStats(startDate, endDate);
    
    // query configurations
    List<ConfigurationInfo> configurations = await UsageStats.queryConfiguration(startDate, endDate);
    
    // query aggregated usage statistics
    Map<String, UsageInfo> queryAndAggregateUsageStats = await UsageStats.queryAndAggregateUsageStats(startDate, endDate);

    // query network usage statistics
    List<NetworkInfo> networkInfos = await UsageStats.queryNetworkUsageStats(startDate, endDate, networkType: NetworkType.all);

}

To DO #

  • Add option to pass Interval Type in queryUsageStats, queryEventStats method
  • Add Unit Tests
36
likes
150
pub points
92%
popularity

Publisher

unverified uploader

Query Android Usage Statistics (Configurations, Events, Usage)

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on usage_stats