dataUsageAndroid static method
Future<List<DataUsageModel> >
dataUsageAndroid({
- bool withAppIcon = false,
- bool oldVersion = false,
- DataUsageType dataUsageType = DataUsageType.mobile,
Gets Data Usage From Android Device as Future<List<DataUsageModel>>
Params:
bool withAppIcon // if false `DataUsageModel.appIconBytes` will be null.
bool oldVersion // will be true for Android versions lower than 23 (MARSHMELLOW)
DataUsageType dataUsageType // Toggle between Wifi and Mobile Data Usage
WARNING
This method only supports Android versions greater than 21 (LOLLIPOP)
For android versions greater than 23 (MARSHMELLOW)
- Call
DataUsageType.init()
first before this to get necesarry permissions
For android versions greater than 21 (LOLLIPOP)
less than 23 (MARSHMELLOW)
:
-
Data resets after every reboot
-
It may also be unsupported on some devices.
Implementation
static Future<List<DataUsageModel>> dataUsageAndroid({
bool withAppIcon = false,
bool oldVersion = false,
DataUsageType dataUsageType = DataUsageType.mobile,
}) async {
if (Platform.isAndroid) {
final List<dynamic> dataUsage = await _channel.invokeMethod(
oldVersion ? 'getDataUsageOld' : 'getDataUsage',
<String, dynamic>{
"withAppIcon": withAppIcon,
"isWifi": dataUsageType == DataUsageType.wifi,
},
);
return dataUsage
.map((e) => DataUsageModel.fromJson(Map<String, dynamic>.from(e)))
.toList();
} else {
//Limit API to Android Platform
print(
PlatformException(
code: 'DATA_USAGE',
message:
'This method can only be called on an android device use .dataUsageIOS() instead',
),
);
return [];
}
}