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:
    Code:
    #Region  Project Attributes
        
    #ApplicationLabel: b4aAndroidDeviceInformation
        
    #VersionCode: 1
        
    #VersionName:
        
    '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:
        Activity.LoadLayout("main")
        freqlist.Initialize
        utillist.Initialize
       
        lv1.Color = 
    Colors.Blue
        lv1.SingleLineLayout.Label.TextSize = 
    15
       
        lv2.Color = 
    Colors.Gray
        lv2.SingleLineLayout.Label.TextSize = 
    15
       
        t.Initialize(
    "t"500)
        adi.Initialize(
    "cpu")

    End Sub

    Sub Activity_Resume
       
        t.Enabled = 
    True

    End Sub

    Sub Activity_Pause (UserClosed As Boolean)
       
        t.Enabled = 
    False

    End Sub

    Sub t_tick
       
        adi.addFrequency
        adi.addCoreUtilization
       
    End Sub

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

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

    Attached Files:

    Last edited: Dec 24, 2017
Loading...
  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