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:

Code: Copy
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

Last edited:
Thank you for writing the OS library.

I have a couple of questions.

I looked at the .xml file and saw the info on reboot but when I use the code

Code: Copy
OS.reboot

It says there is a missing parameter?
 
Thank you for writing the OS library.

I have a couple of questions.

I looked at the .xml file and saw the info on reboot but when I use the code

Code: Copy
OS.reboot

It says there is a missing parameter?

You can reboot the phone without a library using a shell command...
I don't think it requires root. It's what I use in my own apps.
Code: Copy
Dim p As phone
p.Shell("reboot",Null,Null,Null)
 
Code: Copy
Dim p As phone
p.Shell("reboot",Null,Null,Null)

Did not work on my Droid2...perhaps it does require your phone to be rooted?
 
reboot

Hi
what did you write to get the reboot privileges
i tried with:
os.reboot( "-p")
p should be a parameter to shut down !! i hope
and after i get the error of no priv..

thank's
marco
 
I tried it with the "-p" argument and I got an err msg saying I don't have reboot permission. I added a .REBOOT line to my manifest but I still got the you don't have reboot permission error messge.
 
After some testing it's not possible to reboot the device.
I also keep having the same reboot error, though the permission is added.

Here's some more information:
Programmatically switching off Android phone - Stack Overflow

This is the java code i use:
Code: Copy
/**
        * Reboot the device. Will not return if the reboot is successful. 
        * reason   code to pass to the kernel (e.g., "recovery") to request special boot modes, or null.
        * Api level 8
        */
     public void reboot(String Reason) {
        PowerManager pm = (PowerManager)BA.applicationContext.getSystemService(ba.applicationContext.POWER_SERVICE);   
        pm.reboot(Reason);
     }

Kind regards,
Tomas
 
you might be able to do it with an intent

Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
 
I tried compiling your code below but the new keyword is causing an error and shows in the IDE in red.

Error: Error description: Input string was not in a correct format.

Code: Copy
Dim mContext As Int
   
Intent Intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
Intent.putExtra(Intent.EXTRA_KEY_CONFIRM, False);
Intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(Intent);
 
OSLibrary Bug

Hi,

Very nice library, thanks.

It seems the RunningAppProcessInfo function populates both List1 and List3 with the same information, that being the package name and the pid. Instead of List one just containing the package name

Regards
 
1) How exactly works installPackage? What needs for working ?
2) How practically to make java.io.file argument for it ?
3) Is maybe DeletePackage also possible ?
 
It should be in bytes:

StatFs | Android Developers

and thanks,

XverhelstX

Would be helpful if your refined the numbers so they
1. presented in appropriate groupings (i.e. bytes if less than 1,000; kb 1,000 - 1,000,000; mb 1 million to 1 billion; gb 1 billion and above).
2. displays rounded mb and gb values to neaest hundreth (i.e. 1.67gb)
3. have the option for displaying actual (non-rounded) values for mb and gb.

Just a thought.

BTW -- what version of the library are you on now?
 
can we get an example of OS.RunningAppProcessInfo OS.RunningAppProcesses

say putting the list into a label or checkboxes,i find the info a little confusing thanks
 
Many thanks for your useful library! :icon_clap:
 
Thanks for the OS.Library, but I have a problem to read the activity.title of other apps.

This will not do. I only get the activity. Not the title ....


Code: Copy
   Dim OS As OperatingSystem
    
   Dim Tasks As List    
   Tasks = OS.getRunningTasks(1000)
   If Tasks.Size > 0 Then        
   For i = 0 To Tasks.Size - 1            
   Dim r As Reflector
   r.Target = Tasks.Get(i)
   Log(r.GetField("topActivity"))
   Log(r.GetField("baseActivity"))
   Next    
   End If

Can anyone help me?
 
Back
Top