Grabbing the current remaining threshold minutes from a DeviceActivity schedule?

I’d like to display to the user their remaining time but can’t seem to find where to pull this information from.

Answered by Frameworks Engineer in 725522022

While there is not a way to do this directly using a DeviceActivityCenter or any of the DeviceActivityEvent APIs, you can create a DeviceActivityReport and configure its filter so that your app's DeviceActivityReportExtension gets usage data for the tokens in your DeviceActivityEvent. Your extension can then subtract the totalActivityDuration from the event's threshold in seconds to get the remaining amount of time.

Accepted Answer

While there is not a way to do this directly using a DeviceActivityCenter or any of the DeviceActivityEvent APIs, you can create a DeviceActivityReport and configure its filter so that your app's DeviceActivityReportExtension gets usage data for the tokens in your DeviceActivityEvent. Your extension can then subtract the totalActivityDuration from the event's threshold in seconds to get the remaining amount of time.

It appears DeviceActivityReport is a view. Is there a way to extract this information without a view? Is there a code example floating around somewhere? cc: @Kmart

@Kmart thanks for this - I can't quite understand how my DeviceActivityReportExtension can access the data from an event, in order to extract the event threshold? How can this be passed in?

Grabbing the current remaining threshold minutes from a DeviceActivity schedule?
 
 
Q