app_usage 4.0.0 copy "app_usage: ^4.0.0" to clipboard
app_usage: ^4.0.0 copied to clipboard

PlatformAndroid

App usage plugin for Android only, which can be used to get the time spent by the user in each app.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:app_usage/app_usage.dart';

void main() => runApp(AppUsageApp());

class AppUsageApp extends StatefulWidget {
  @override
  AppUsageAppState createState() => AppUsageAppState();
}

class AppUsageAppState extends State<AppUsageApp> {
  List<AppUsageInfo> _infos = [];

  @override
  void initState() {
    super.initState();
  }

  void getUsageStats() async {
    try {
      DateTime endDate = DateTime.now();
      DateTime startDate = endDate.subtract(Duration(hours: 1));
      List<AppUsageInfo> infoList =
          await AppUsage().getAppUsage(startDate, endDate);
      setState(() => _infos = infoList);
    } catch (exception) {
      print(exception);
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('App Usage Example'),
          backgroundColor: Colors.green,
        ),
        body: ListView.builder(
            itemCount: _infos.length,
            itemBuilder: (context, index) {
              return ListTile(
                  title: Text(_infos[index].appName),
                  trailing: Text(_infos[index].usage.toString()));
            }),
        floatingActionButton: FloatingActionButton(
            onPressed: getUsageStats, child: Icon(Icons.file_download)),
      ),
    );
  }
}
copied to clipboard
80
likes
160
points
1.03k
downloads

Publisher

verified publishercachet.dk

Weekly Downloads

2024.09.13 - 2025.03.28

App usage plugin for Android only, which can be used to get the time spent by the user in each app.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on app_usage