B4A Library OS Library

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:

B4X:
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
 

Attachments

  • OSLibraryV13.zip
    18.3 KB · Views: 1,948
  • OSLibrary1.4.zip
    13.9 KB · Views: 3,887
Last edited:

XverhelstX

Well-Known Member
Licensed User
Longtime User
@Erel or agraham:

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

B4X:
/**
      * 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
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
Thanks a lot Erel!
Here's some example code:
B4X:
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:

B4X:
Msgbox(OS.RunningAppProcesses,"Processes")

I receive the following information:

[android.app.ActivityManager$RunningAppProcessInfo@2b049558, android.app.ActivityManager$RunningAppProcessInfo@2b049688, android.app.ActivityManager$RunningAppProcessInfo@2b049788, android.app.ActivityManager$RunningAppProcessInfo@2b049a70, android.app.ActivityManager$RunningAppProcessInfo@2b049cb0, android.app.ActivityManager$RunningAppProcessInfo@2b049f00, android.app.ActivityManager$RunningAppProcessInfo@2b04a138, android.app.ActivityManager$RunningAppProcessInfo@2b04a2b8, android.app.ActivityManager$RunningAppProcessInfo@2b04a408, android.app.ActivityManager$RunningAppProcessInfo@2b04a568, android.app.ActivityManager$RunningAppProcessInfo@2b04a688, android.app.ActivityManager$RunningAppProcessInfo@2b04a7b8, android.app.ActivityManager$RunningAppProcessInfo@2b04a8e8, android.app.ActivityManager$RunningAppProcessInfo@2b04aa30, android.app.ActivityManager$RunningAppProcessInfo@2b04ab60, android.app.ActivityManager$RunningAppProcessInfo@2b04ac90, android.app.ActivityManager$RunningAppProcessInfo@2b04adc0, android.app.ActivityManager$RunningAppProcessInfo@2b04aed0, android.app.ActivityManager$RunningAppProcessInfo@2b04b010, android.app.ActivityManager$RunningAppProcessInfo@2b04b328, android.app.ActivityManager$RunningAppProcessInfo@2b04b590, android.app.ActivityManager$RunningAppProcessInfo@2b04b848, android.app.ActivityManager$RunningAppProcessInfo@2b04b958, android.app.ActivityManager$RunningAppProcessInfo@2b04ba48, android.app.ActivityManager$RunningAppProcessInfo@2b04bca8, android.app.ActivityManager$RunningAppProcessInfo@2b04bdc8, android.app.ActivityManager$RunningAppProcessInfo@2b04bee8, android.app.ActivityManager$RunningAppProcessInfo@2b04c030, android.app.ActivityManager$RunningAppProcessInfo@2b04c150, android.app.ActivityManager$RunningAppProcessInfo@2b04c270, android.app.ActivityManager$RunningAppProcessInfo@2b04c3d0, android.app.ActivityManager$RunningAppProcessInfo@2b04c4e0, android.app.ActivityManager$RunningAppProcessInfo@2b04c618, android.app.ActivityManager$RunningAppProcessInfo@2b04c768, android.app.ActivityManager$RunningAppProcessInfo@2b04c8d0, android.app.ActivityManager$RunningAppProcessInfo@2b04ca50, android.app.ActivityManager$RunningAppProcessInfo@2b04cbb0, android.app.ActivityManager$RunningAppProcessInfo@2b04cce0, android.app.ActivityManager$RunningAppProcessInfo@2b04ce30, android.app.ActivityManager$RunningAppProcessInfo@2b04cf60, android.app.ActivityManager$RunningAppProcessInfo@2b04d0b0, android.app.ActivityManager$RunningAppProcessInfo@2b04d1c0, android.app.ActivityManager$RunningAppProcessInfo@2b04d2d0, android.app.ActivityManager$RunningAppProcessInfo@2b04d548, android.app.ActivityManager$RunningAppProcessInfo@2b04d678, android.app.ActivityManager$RunningAppProcessInfo@2b04d7b0, android.app.ActivityManager$RunningAppProcessInfo@2b04d8e0]

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

Thanks

XverhelstX
 

NJDude

Expert
Licensed User
Longtime 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.
 

magarcan

Active Member
Licensed User
Longtime User
Are there any function, for example about flashing recovery, making wipes or some similar??
 
Last edited:

NJDude

Expert
Licensed User
Longtime 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.
 

guidoarfini

Member
Licensed User
Longtime 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
 

Cableguy

Expert
Licensed User
Longtime User
Is there any methods to get the device's Scale factor and Screen Physical Size?
 

XverhelstX

Well-Known Member
Licensed User
Longtime 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:
Top