B4A Library Device Information

Discussion in 'Additional libraries, classes and official updates' started by Johan Schoeman, Dec 24, 2017.

  1. Johan Schoeman

    Johan Schoeman Expert Licensed User

    Was a bit bored today and thought that I will try and do something like THIS. I found a Github Project that was able to provide me with some CPU information:

    (Displayed in ListView1 of the attached project)
    1. Maximum CPU Frequency
    2. Minimum CPU Frequency
    3. Current CPU Frequency

    (Displayed in ListView2 of the attached project)
    1. The number of cores
    2. Combined utilization of all cores (%)
    3 to x. The utilization of each individual core (%)

    The two ListViews are updated every 500ms via a timer.

    There are lots more functionality in the Github project but I was only interested in some of the CPU info. Have tested it on two devices and seems to be working....

    Sample Code:
    #Region  Project Attributes
    #ApplicationLabel: b4aAndroidDeviceInformation
    #VersionCode: 1
    'SupportedOrientations possible values: unspecified, landscape or portrait.
        #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
    #End Region

    #Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
    #End Region

    Sub Process_Globals
    'These global variables will be declared once when the application starts.
        'These variables can be accessed from all modules.
    Dim t As Timer

    End Sub

    Sub Globals
    'These global variables will be redeclared each time the activity is created.
        'These variables can only be accessed from this module.
    Dim adi As AndroidDeviceInformation
    Dim freqlist As List
    Dim utillist As List

    Private lv1 As ListView
    Private lv2 As ListView
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
        lv1.Color = 
        lv1.SingleLineLayout.Label.TextSize = 
        lv2.Color = 
        lv2.SingleLineLayout.Label.TextSize = 

    End Sub

    Sub Activity_Resume
        t.Enabled = 

    End Sub

    Sub Activity_Pause (UserClosed As Boolean)
        t.Enabled = 

    End Sub

    Sub t_tick
    End Sub

    Sub cpu_found_frequency(freq As Object)
        freqlist = freq
    "MaxCpuFreq = " & freqlist.Get(0))
    "MinCpuFreq = " & freqlist.Get(1))
    "CurrentCpuFreq = " & freqlist.Get(2))
    End Sub

    Sub cpu_core_utilization(percentage As Object)
        utillist = percentage
    "No of Cores = " & utillist.Get(0))
    "Utilization All Cores = " & utillist.Get(1))
    For i = 2 To utillist.Size - 1
    "Utilization Core " & (i-2) & " = " & utillist.Get(i))
    End Sub

    Attached Files:

    Last edited: Dec 24, 2017
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice