Search This Blog

Showing posts with label OS/kernel. Show all posts
Showing posts with label OS/kernel. Show all posts

Thursday, February 16, 2012

Read AndroidOS version info., using System.getProperty Method

Now this is the another class of reading the android Os version info with the getProperty Method.

Make an .xml file with the following code.


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 >
<TextView
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:text="Android System:"
 />
<TextView
 android:id="@+id/SYSinfo"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 />
</LinearLayout>

Now make the java file for the getProperty method with the following code.



public class OSversion extends Activity{


@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.osversion);
TextView SYSinfo = (TextView) findViewById(R.id.SYSinfo);
    SYSinfo.setText(ReadSYSinfo());
}


private static StringBuffer SYSinfoBuffer;


private String ReadSYSinfo()
{
 SYSinfoBuffer = new StringBuffer();
 
 getProperty("os.name", "os.name", SYSinfoBuffer);
 getProperty("os.version", "os.version", SYSinfoBuffer);
 
 getProperty("java.vendor.url", "java.vendor.url", SYSinfoBuffer);
 getProperty("java.version", "java.version", SYSinfoBuffer);
 getProperty("java.class.path", "java.class.path", SYSinfoBuffer);
 getProperty("java.class.version", "java.class.version", SYSinfoBuffer);
 getProperty("java.vendor", "java.vendor", SYSinfoBuffer);
 getProperty("java.home", "java.home", SYSinfoBuffer);
 
 getProperty("user.name", "user.name", SYSinfoBuffer);
 getProperty("user.home", "user.home", SYSinfoBuffer);
 getProperty("user.dir", "user.dir", SYSinfoBuffer);
 
 return SYSinfoBuffer.toString();
}


private void getProperty(String name, String property, StringBuffer tBuffer)
{
 tBuffer.append(name);
 tBuffer.append(" : ");
 tBuffer.append(System.getProperty(property));
 tBuffer.append("\n");
}
}



Here is the output of the above code



How to Read OS/kernel Version

First of all make an .xml file and put the following code into it.


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="typicaljava.blogspot.com"
android:autoLink="web"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Android OS:"
/>
<TextView
android:id="@+id/OSinfo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>


Now make a JAVA file and put the following code below.



public class ReadOSVersionActivity extends Activity {
/** Called when the activity is first created. */
       @Override
       public void onCreate(Bundle savedInstanceState) {
                  super.onCreate(savedInstanceState);
                  setContentView(R.layout.main);


                 TextView OSinfo = (TextView) findViewById(R.id.OSinfo);
                 OSinfo.setText(ReadOSinfo());

        }



         private String ReadOSinfo()
        {
             ProcessBuilder cmd;
             String result="";

             try{

                        String[] args = {"/system/bin/cat", "/proc/version"};
                        cmd = new ProcessBuilder(args);

                           


                        Process process = cmd.start();

                        InputStream in = process.getInputStream();
                        byte[] re = new byte[1024];
                        while(in.read(re) != -1){
                        System.out.println(new String(re));
                        result = result + new String(re);
                }
                in.close();
           } 
           catch(IOException ex)
          {
               ex.printStackTrace();
           }
        return result;
     }
}


you'll get the following output.