This is a fork of https://github.com/bright-hustle/react-native-usage-stats-manager The goal of this fork is to provide a very simple bridge between Android UsageStats and react-native, without any custom aggregation. Instead the raw usage stats and events are made available in react-native.
npm install @justdice/react-native-usage-statsPermission need to be added on AndroidManifest.xml
<uses-permissionandroid:name="android.permission.PACKAGE_USAGE_STATS" />
If Build Error on kotlin add kotlinVersion to the gradle.properties
kotlinVersion=1.8.10
import{EventFrequency,checkForPermission,queryUsageStats,showUsageAccessSettings,}from'@justdice/react-native-usage-stats';TimeneedstobeinmillisecondforfunctionqueryUsageStatsconststartDateString='2023-06-11T12:34:56';constendDateString='2023-07-11T12:34:56';conststartMilliseconds=newDate(startDateString).getTime();constendMilliseconds=newDate(endDateString).getTime();constresult=awaitqueryUsageStats(EventFrequency.INTERVAL_DAILY,startMilliseconds,endMilliseconds)checkForPermission().then((res: any)=>{if(!res){showUsageAccessSettings('');}});See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT
Made with create-react-native-library