This is a wrap for androids UsageStatsManager
UsageStatsManager
Author: DonManfred (wrapper)
Version: 1
Sample code
- Please note the Permission inside Manifest!
- Please note that you need to Add you App to the Exceptionlist in your Android Security settings.
Settings/Security/Allow app use of Usage stats
Add your app to the list...
UsageStatsManager
Author: DonManfred (wrapper)
Version: 1
- UsageStats
Methods:- Initialize (usageStats As UsageStats)
- IsInitialized As Boolean
- FirstTimeStamp As Long [read only]
- LastTimeStamp As Long [read only]
- LastTimeUsed As Long [read only]
- PackageName As String [read only]
- TotalTimeInForeground As Long [read only]
- describeContents As Int [read only]
- UsageStatsManager
Methods:- Initialize (EventName As String)
- IsInitialized As Boolean
- queryAndAggregateUsageStats (start As Long, end As Long) As Map
- queryUsageStats (start As Long, end As Long) As List
Sample code
B4X:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim usm As UsageStatsManager
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
usm.Initialize("")
Log(DateTime.Now)
Dim starttime As Long
starttime = DateTime.DateParse("10/20/2016")
Dim endtime As Long
endtime = DateTime.Now
Dim usage1 As List = usm.queryUsageStats(starttime,endtime)
For i = 0 To usage1.Size-1
Dim us As UsageStats = usage1.Get(i)
Log(us)
Next
Dim usage2 As Map = usm.queryAndAggregateUsageStats(starttime,endtime)
Log(usage2)
End Sub
- Please note the Permission inside Manifest!
- Please note that you need to Add you App to the Exceptionlist in your Android Security settings.
Settings/Security/Allow app use of Usage stats
Add your app to the list...