Class UsageService

  • All Implemented Interfaces:

    
    public final class UsageService
    extends MobileService
                        

    Represents the usage service to handle all usage related tasks.

    By default, UsageService will manage the usage session automatically, An event of 'session start' event will be recorded in the following cases:

    • the usage service is started again with startUsageBroker, at this time, a new session will be started after ending the old one.

    • recording events with the functions start with 'event', or logDeviceInfoEvents if there is no open session.

    An event of 'session end' will be recorded when the app is put into background, or the usage service is stopped with stopUsageBroker.

    The client code can also disable the 'auto session' feature at any time. If 'auto session' feature is disabled, using any of the event log functions here will also log a 'session start' automatically if no session started yet. But it's the client code's responsibility to record the session start and session end event.

    When uploading the usage data, the current session without a 'session end' will NOT be uploaded. By default, UsageService also enables the 'auto upload' feature. The 'auto upload' might happen after a 'session end' is recorded and the record count exceeds the threshold of recordCount.

    After a 'session start' event recorded, functions like eventStart, event, eventEnd, eventBehaviorUserInteraction, eventBehaviorViewDisplayed and logDeviceInfoEvents can be used to log events.

    eventStart and eventEnd can help the client code determine the duration of a group operations. To use this feature, make sure the two functions are invoked with the same 'key' argument value. for example:

    SDKInitializer.getService(UsageService::class)?.also { srv ->
        srv.eventStart(key = EVENT_KEY, info = AppUsageInfo().screen(VIEW_ID))
        srv.eventBehaviorUserInteraction(
            viewId = VIEW_ID,
            action = item.title.toString()
        )
        srv.event(key = EVENT_KEY, info = AppUsageInfo().action("test_event_action"))
        srv.eventEnd(key = EVENT_KEY, info = AppUsageInfo().action("test_event_end_action"))
    }