Parassharmaa / usage_stats

Flutter Plugin to query Android Usage Statistics (Configurations, Events, Usage, Network)
MIT License
15 stars 21 forks source link

Plugin does not give stats in real time #22

Closed Djihanegh closed 2 years ago

Djihanegh commented 2 years ago

Hello,

I"am using this plugin to get stats about the apps on android device, when i open Youtube app for example, it doesn't update the getLastUsed to the last real opened time ! for example if i opened it at 10AM then i open youtube again in 11AM (while the app is running) here it doesnt get updated it returns 10AM...

    DateTime endDate = DateTime.now();
    DateTime startDate =
       DateTime(endDate .year, endDate .month, endDate .day , endDate .hour,endDate .minute, endDate .second-5);

    List<UsageInfo> t = await UsageStats.queryUsageStats(startDate , endDate );

any solution to that ?

Parassharmaa commented 2 years ago

To update it frequently, you may call the method using Timer for e.g:

Timer.periodic(const Duration(seconds: 5), fetchQueryStats());

where fetchQueryStats is a function that loads data. This way after every 5 seconds the data will be refreshed.