Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 60 additions & 32 deletions App.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,100 @@
import { Pressable, StyleSheet, Text, View } from 'react-native'
import React, { useState } from 'react'
import {
Pressable,
ScrollView,
StyleSheet,
Text,
View,
NativeModules,
} from 'react-native';
import React, { useEffect, useState } from 'react'
import {
EventFrequency,
checkForPermission,
queryUsageStats,
showUsageAccessSettings,
queryEventsStats,
queryAndAggregateUsageStats,
queryEvents,
getAppDataUsage
} from '@brighthustle/react-native-usage-stats-manager';

import moment from 'moment'

const App = () => {

const [dataApps, setDataApp] = useState();

const startDateString = '2024-03-17T06:00:00';
const endDateString = '2024-03-18T06:00:00';
const startDateString = '2024-05-15T11:59:00';
const endDateString = '2024-05-16T12:00:00';

const startMilliseconds = new Date(startDateString).getTime();
const endMilliseconds = new Date(endDateString).getTime();

const functionLog = async () => {
const result = await queryUsageStats(
EventFrequency.INTERVAL_DAILY,
startMilliseconds,
endMilliseconds
)
const [startTimeHuman, setStartTimeHuman] = useState('');
const [endTimeHuman, setEndTimeHuman] = useState('');

const functionLog = async () => {
const result = await queryEvents(
// EventFrequency.INTERVAL_DAILY,
startMilliseconds,
endMilliseconds
)

console.log(JSON.stringify(result, null, ' '))
setDataApp(JSON.stringify(result, null, ' '))
}
const startConvert = new Date(startMilliseconds);
const endConvert = new Date(endMilliseconds);

setStartTimeHuman(moment(startConvert).format('DD-MM-yyyy hh:mm:ss'))
setEndTimeHuman(moment(endConvert).format('DD-MM-yyyy hh:mm:ss'))
setDataApp(JSON.stringify(result, null, ' '))
console.info('ARRAY APP USAGE')
console.log(JSON.stringify(result, null, ' '))
}

return (
<View
style={{
margin: 20
}}
>
style={{
margin: 20,
}}>
<Pressable
onPress={() => {
checkForPermission().then((res) => {
checkForPermission().then(res => {
if (!res) {
showUsageAccessSettings('');
} else {
functionLog()
functionLog();
}
});
}}
>
}}>
<View
style={{
style={{
backgroundColor: 'blue',
borderRadius: 5
}}
>
borderRadius: 5,
}}>
<Text
style={{
style={{
color: 'white',
textAlign: 'center',
margin: 7,
}}
>Fetch Data Log Apps</Text>
}}>
Fetch Data Log Apps
</Text>
</View>
</Pressable>

<View style={{flexDirection: 'row'}}>
<Text style={{flex: 1, color: 'black'}}>Start: {startTimeHuman}</Text>
<Text style={{flex: 1, color: 'black'}}>End: {endTimeHuman}</Text>
</View>

<Text>
{dataApps}
</Text>
<ScrollView
style={{ marginBottom: 30 }}
>
<View>
<Text style={{color: 'black'}}>{dataApps}</Text>
</View>
</ScrollView>
</View>
)
);
}

export default App;
58 changes: 33 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,52 @@
# App Usage Tracker v1.0-beta
Log Aplikasi masih baru di Android, untuk iOS masih on ReSearch
# App Usage Tracker v1.1-beta
Log Aplikasi masih baru di Android, untuk iOS masih on ReSearch.

## What's new?
- Modify: Get data by range data (start and end date) usage app (activity)
- Fix: View dan list with scroll

## Log Data Usage Activity
Berikut contoh data yang sudah berhasil diambil dari usage penggunaan activity pada Ponsel Android

```.sh
INFO ARRAY APP USAGE
LOG {
"com.google.android.gms": {
"appName": "Layanan Google Play",
"packageName": "com.google.android.gms",
"lastTimeUsed": 1715759957978,
"firstTimeStamp": 1715678603628,
"0": {
"isSystem": false,
"totalTimeInForeground": 21,
"lastTimeStamp": 1715765003627
"count": 13,
"eventType": 0,
"usageTime": 6540838,
"eventTime": 1715766609656,
"packageName": "ginlemon.flowerfree",
"humanReadableUsageTime": "1h 49m 0s",
"name": "ginlemon.flowerfree"
},
"com.burockgames.timeclocker": {
"appName": "com.burockgames.timeclocker",
"packageName": "com.burockgames.timeclocker",
"lastTimeUsed": 1715761629904,
"firstTimeStamp": 1715678603628,
"1": {
"isSystem": false,
"totalTimeInForeground": 104,
"lastTimeStamp": 1715765003627
"count": 3,
"eventType": 0,
"usageTime": 911078,
"eventTime": 1715766595356,
"packageName": "com.rnappusage",
"humanReadableUsageTime": "15m 11s",
"name": "RNAppUsage"
},
"com.android.deskclock": {
"appName": "Jam",
"packageName": "com.android.deskclock",
"lastTimeUsed": 1715630340415,
"firstTimeStamp": 1715592200825,
"2": {
"isSystem": false,
"totalTimeInForeground": 179,
"lastTimeStamp": 1715678600824
"count": 5,
"eventType": 0,
"usageTime": 632758,
"eventTime": 1715765845264,
"packageName": "com.facebook.katana",
"humanReadableUsageTime": "10m 32s",
"name": "Facebook"
},
. . . .
// And more data
```

Dan berikut tampilannya

<img src="https://github.com/aspsptyd/rn-app-usage-tracker/assets/98740335/fe442858-552f-4e3b-a4b1-5e582bce8521" width="300"/>
<img src="https://github.com/aspsptyd/rn-app-usage-tracker/assets/98740335/0cf57191-35ef-4d8d-af8f-4b1a248a2886" width="300"/>
<br /><br />

Copyright &copy; 2024 Asep Septiadi. All right reserved. Powered by <a href="https://www.npmjs.com/package/@brighthustle/react-native-usage-stats-manager">`react-native-usage-stats-manager`</a>
8 changes: 8 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,10 @@ PODS:
- React-Mapbuffer (0.73.6):
- glog
- React-debug
- react-native-usage-stats-manager (0.1.5):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- React-nativeconfig (0.73.6)
- React-NativeModulesApple (0.73.6):
- glog
Expand Down Expand Up @@ -1167,6 +1171,7 @@ DEPENDENCIES:
- React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector-modern`)
- React-logger (from `../node_modules/react-native/ReactCommon/logger`)
- React-Mapbuffer (from `../node_modules/react-native/ReactCommon`)
- "react-native-usage-stats-manager (from `../node_modules/@brighthustle/react-native-usage-stats-manager`)"
- React-nativeconfig (from `../node_modules/react-native/ReactCommon`)
- React-NativeModulesApple (from `../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios`)
- React-perflogger (from `../node_modules/react-native/ReactCommon/reactperflogger`)
Expand Down Expand Up @@ -1261,6 +1266,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/logger"
React-Mapbuffer:
:path: "../node_modules/react-native/ReactCommon"
react-native-usage-stats-manager:
:path: "../node_modules/@brighthustle/react-native-usage-stats-manager"
React-nativeconfig:
:path: "../node_modules/react-native/ReactCommon"
React-NativeModulesApple:
Expand Down Expand Up @@ -1344,6 +1351,7 @@ SPEC CHECKSUMS:
React-jsinspector: 85583ef014ce53d731a98c66a0e24496f7a83066
React-logger: 3eb80a977f0d9669468ef641a5e1fabbc50a09ec
React-Mapbuffer: 84ea43c6c6232049135b1550b8c60b2faac19fab
react-native-usage-stats-manager: 3571268b9473458a9f15d4a2af8661f8c544b0cc
React-nativeconfig: b4d4e9901d4cabb57be63053fd2aa6086eb3c85f
React-NativeModulesApple: cd26e56d56350e123da0c1e3e4c76cb58a05e1ee
React-perflogger: 5f49905de275bac07ac7ea7f575a70611fa988f2
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
},
"dependencies": {
"@brighthustle/react-native-usage-stats-manager": "^0.1.5",
"moment": "^2.30.1",
"react": "18.2.0",
"react-native": "0.73.6"
"react-native": "0.73.6",
"react-native-app-usage-monitor": "^1.0.0"
},
"devDependencies": {
"@babel/core": "^7.20.0",
Expand Down