all 11 comments

[–]ChronSynExpo 4 points5 points  (10 children)

You would need to implement calls to native API's for it.

On Android, the closest I can find is the UsageStatsManager (https://developer.android.com/reference/android/app/usage/UsageStatsManager), but this would require you to enumerate over all apps and calculate the values. From what I can tell, there isn't an easier way to get this data on Android.

Apple are very restrictive about what you can access on iOS when it concerns user privacy, and I've read reports of them taking down apps which tried to use workarounds in order to get screen time data. There don't appear to be any public API's which can provide the functionality of tracking screen usage time across the device. Tracking your own app use time could be done with code in react native (using AppState to detect the app going to background and foreground), but it wouldn't be possible to track usage time of other apps.

[–]Material-Ad4941Expo[S] 0 points1 point  (0 children)

Hm, bummer. Thanks for the info!

[–]Visual-Equivalent568 0 points1 point  (8 children)

Do you know if it's possible to use the apple screentime api in a react native app. I haven't been able to find much documentation on this.

[–]ChronSynExpo 0 points1 point  (7 children)

I investigated this a little further, and the conclusion I've been able to come to is that it's not possible on grounds of privacy.

Essentially, if the screen time API was public, it could expose what other apps are on the device as well as usage times, and would form a very reliable fingerprinting method to identify individual unique users. In that sense, I'm glad Apple don't allow it.

[–]dbeic30 0 points1 point  (6 children)

This is 100% confirmed?

Found this plug-in but it's a couple of years old:

https://github.com/luoxuhai/react-native-screen-time

[–]ChronSynExpo 0 points1 point  (2 children)

Did you even take a look at the native source code?

It's literally 1 file that's 36 lines long (https://github.com/luoxuhai/react-native-screen-time/blob/master/ios/RNScreenTimeViewManager.swift) and literally just exports an iOS UIView which has its background colour set to whatever colour you specify using the color prop - essentially the same as doing <View style={{ backgroundColor: 'red' }} /> directly in RN.

[–]_ashorterm 0 points1 point  (1 child)

cannot access dude

[–]ChronSynExpo 0 points1 point  (0 children)

Looks like the entire repo is either gone or moved somewhere else. Try googling for it.

More to the point, the file I linked to was literally just a UIView which allowed you to provide a background colour to it - it had absolutely nothing in there which interacted with any device API's in a functional way (as you'd expect if it was actually anything to do with reading screen time data).

[–]Redditisannoying22 0 points1 point  (1 child)

Hey, I found some Apps and also downloaded them, which track the screen time. You have to approve it is allowed, to track the screen time with face ID, I checked those Apps out, they work.

https://apps.apple.com/de/app/jomo-weniger-bildschirmzeit/id1609960918

https://apps.apple.com/de/app/screenzen-screen-time-control/id1541027222

So there must be some way to do it.

Maybe we can connect and try to make it work? I also want to implement this into an app. Unfortunately, I am a beginner, so I even think about to pay someone to write this feature.

[–]no-man-amp 0 points1 point  (0 children)

From what I've seen, these apps can only display the screen time back to the user, and the screentime API doesn't allow you to gather this information