app_data_usage 1.0.1 copy "app_data_usage: ^1.0.1" to clipboard
app_data_usage: ^1.0.1 copied to clipboard

PlatformAndroid

A Flutter plugin to check daily data usage(both wifi and mobile) for the installed app. Only support for android currently as iOS doesn't allow to query this.

app_data_usage #

A Flutter plugin to check daily data usage(both wifi and mobile) for the installed app. Only support for android currently as iOS doesn't allow to query this.

Install #

Add app_data_usage as a dependency in pubspec.yaml.

Android #

Requires API level 23 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" />

Your project manifest should look like this.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.app_data_usage_example">
    <uses-permission
        android:name="android.permission.PACKAGE_USAGE_STATS"
        tools:ignore="ProtectedPermissions" />

Usage #

import 'package:app_data_usage/app_data_usage.dart';

Future<void> checkPermission() async {
    try {
      final granted = await AppDataUsage.instance.checkPermission();
    } catch (e) {
      //get error if thrown
    }
}

Future<bool?> requestPermission() async {
    final granted = await checkPermission();
    if (granted) return null;
    return await AppDataUsage.instance.requestPermission();
}

Future<void> checkDailyDataUsage() async {
    final details = await AppDataUsage.instance.getDailyDataUsageForApp();
    print('details: ${details.toJson()}');
    if (!details.isSuccess) return; //check details.error for error message
    var rxTotalBytes = details.rxBytes;
    var txTotalBytes = details.txBytes;
}

Check example project in repo if you have any concerns. Repo

For issues > Issues

1
likes
160
points
78
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin to check daily data usage(both wifi and mobile) for the installed app. Only support for android currently as iOS doesn't allow to query this.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on app_data_usage