B4A Library OS Library

Discussion in 'Additional libraries, classes and official updates' started by XverhelstX, Sep 2, 2011.

  1. XverhelstX

    XverhelstX Well-Known Member Licensed User

    Hello everyone,

    I present you thé OS Lib. aka. the Operating System Library.:sign0025:
    This 'giant' library has around 60+ commands.
    Everything is explained in the library itself.

    What does it cover:

    - Memory size of directories
    - Tons of hardware strings (e.g model, device, host, ...)
    - A unique, very easy countdown timer with 2 events (easier than timer :sign0103:

    Code:
    Dim OS As OperatingSystem
    OS.Initialize(
    "OS")
    OS.CountDownTimer(
    1000)

    Sub OS_ontick (ms as long)
           
    toastmessageshow(ms,false)
    end sub

    Sub OS_onfinish (OS As String)
       
    Msgbox(OS,"OS Library"'get the secret message in here ;)
    End Sub
    - CPU information
    - Running services, tasks, sending signals
    - Rebooting (and wiping data)
    - and a lot more!

    Note that it is still in beta and errors may still occur. ( I haven't tested all functions yet.)
    Please tell it here when, why, what, etc happened.
    It is also possible that I didn't add a certain permission as I can't find them always.

    I like feedback as it gives me more motivation. :D
    (now go and make your own task killer :^))


    Cheerz!
    Tomas
     

    Attached Files:

    Last edited: Nov 6, 2011
  2. thedesolatesoul

    thedesolatesoul Expert Licensed User

  3. XverhelstX

    XverhelstX Well-Known Member Licensed User

    :wav:

    Updated to V1.1
    Now you can calculate your CPU usage with calculateCPUusage :sign0060:
     
  4. XverhelstX

    XverhelstX Well-Known Member Licensed User

    @Erel or agraham:

    I seem to have a Nullpointerexception when I retrieve the currentProcesses, etc.

    Code:
    /**
          * Returns a 
    list of application processes that are running on the device.
          * 
          * @
    return
          */
         
    public List<ActivityManager.RunningAppProcessInfo> getRunningAppProcesses () {
            ActivityManager am = (ActivityManager)ba.activity.getSystemService(Context.ACTIVITY_SERVICE);
            
    List<ActivityManager.RunningAppProcessInfo> l = am.getRunningAppProcesses();
            
    return l; 
         }
    The error is related to here:
    getRunningAppProcesses () {
    ActivityManager am = (ActivityManager)ba.activity.getSystemService(Context.ACTIVITY_SERVICE);

    Any idea? :s

    XverhelstX
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    ba.activity is only available if you declare your object with @ActivityObject.
    You do not need it here.
    Instead use: BA.applicationContext.
    This is the static context which is always available.
     
  6. XverhelstX

    XverhelstX Well-Known Member Licensed User

    Thanks a lot Erel!
    Here's some example code:
    Code:
    Msgbox(OS.AvailableExternalMemorySize,OS.AvailableInternalMemorySize)
    Msgbox(OS.AvailableMemory,OS.Board)
    Msgbox(OS.CPUABI,OS.Host)
    Msgbox(OS.myPid,OS.myTid)
    Msgbox(OS.RunningAppProcesses,"Processes")
    Msgbox(OS.ReadCPUinfo,"Processes")
    Msgbox(OS.RunningAppProcess,OS.Time)
    Msgbox(OS.formatSize(256),"FormatSize")

    Msgbox(OS.getRunningServices(10),"Running Services")
    Msgbox(OS.getRunningTasks(10),"Running Tasks")
    OS.killProcess(OS.myPid)
    It works, however, I still have a question:

    Using this:

    Code:
    Msgbox(OS.RunningAppProcesses,"Processes")
    I receive the following information:

    How can I 'interpretate' this?
    Is it possible to get names, etc out of it?

    Thanks

    XverhelstX
     
  7. XverhelstX

    XverhelstX Well-Known Member Licensed User

    Ok, I found it.
    I will add new methodes where you will be able to retrieve the pid and the process name, etc
    I will update it later.

    XverhelstX
     
  8. XverhelstX

    XverhelstX Well-Known Member Licensed User

    Updated!

    Now you can read different things like Processorname, etc with OS.ReadCPUinfo.

    Also you can now retrieve the pid and process, service and task names!

    XverhelstX
     
  9. NJDude

    NJDude Expert Licensed User

    First of all, very cool lib, thanks.

    Question, regarding memory, the number obtained is what? bytes? KB? MB?, I think you should add a little bit more info about that.

    I'm gonna keep testing and let you know what I find.
     
  10. XverhelstX

    XverhelstX Well-Known Member Licensed User

  11. NeoTechni

    NeoTechni Well-Known Member Licensed User

    Can it enumerate installed apps and extract icons from them?
     
  12. Erel

    Erel Administrator Staff Member Licensed User

  13. magarcan

    magarcan Active Member Licensed User

    Are there any function, for example about flashing recovery, making wipes or some similar??
     
    Last edited: Sep 12, 2011
  14. NJDude

    NJDude Expert Licensed User

    I haven't tested all of them, but some make the app crash, and others don't show any results, 2 quick examples, "BatteryLevel" returns nothing and "AvailableMemory" returns Zero.

    I'll try to make a detailed list.
     
  15. guidoarfini

    guidoarfini Member Licensed User

    can i help me?

    Could you help me please? I would like to make a simple countdown visuallizzato the label and can be set as a text box ... Thanks in advance ..

    my code

    Activity module
    Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

    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 label1 As Label
    Dim BtnStart As Button
    Dim OS As OperatingSystem
    Dim EditValue As EditText
    End Sub

    Sub Activity_Create(FirstTime As Boolean)

    activity.LoadLayout("startpage")
    OS.Initialize("OS")
    EditValue.Text = ("")
    label1.Text=("insert value")

    End Sub

    Sub OS_ontick (ms As Long)
    ToastMessageShow(ms,False)
    End Sub

    Sub OS_onfinish (OS As String)
    Msgbox(OS,"OS Library") 'get the secret message in here ;)
    End Sub


    Sub Activity_Resume

    End Sub

    Sub Activity_Pause (UserClosed As Boolean)

    End Sub

    Sub BtnStart_Click
    If EditValue.Text=("") Then
    Msgbox("alert","insert Value")
    Else
    OS.CountDownTimer(EditValue.text)
    End If
    label1.Text=os.CountDownTimer
    End Sub
     
  16. XverhelstX

    XverhelstX Well-Known Member Licensed User

    Can you upload your whole project?

    File - Export as ZIP.

    Upload here.

    Thanks

    Tomas
     
  17. guidoarfini

    guidoarfini Member Licensed User

    tank you for your time...
     

    Attached Files:

  18. XverhelstX

    XverhelstX Well-Known Member Licensed User

    What do you actually need? :eek:
    What should happen.

    Tomas
     
  19. Cableguy

    Cableguy Expert Licensed User

    Is there any methods to get the device's Scale factor and Screen Physical Size?
     
  20. XverhelstX

    XverhelstX Well-Known Member Licensed User

    Updated to 1.4.
    I hope this is what you are after Cableguy.

    Includes:

    - density: The logical density of the display.
    - densityDpi: The screen density expressed as dots-per-inch.
    - heightPixels: The absolute height of the display in pixels.
    - scaledDensity: A scaling factor for fonts displayed on the display.
    - widthPixels: The absolute width of the display in pixels.
    - xdpi :The exact physical pixels per inch of the screen in the X dimension.
    - ydpi :The exact physical pixels per inch of the screen in the Y dimension.

    I also added physicalScreenWidth and physicalScreenHeight.
    = xdpi * widthPixels and ydpi * heightPixels.

    Tomas
     
    Last edited: Nov 6, 2011
    NicW likes this.

Share This Page

Loading...