Search This Blog

Thursday, February 16, 2012

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.





No comments:

Post a Comment

Note: Only a member of this blog may post a comment.