Process p;
        try {
            // Preform su to get root privledges
            p = Runtime.getRuntime().exec("su");

            // Attempt to write a file to a root-only
            DataOutputStream os = new DataOutputStream(p.getOutputStream());
            os.writeBytes("echo \"Do I have root?\" 
>/system/sd/temporary.txt\n");

            // Close the terminal
            os.writeBytes("exit\n");
            os.flush();
            try {
                p.waitFor();
                if (p.exitValue() != 255) {
                    // TODO Code to run on success
                    Toast.makeText(getContext(), "root", Toast.LENGTH_LONG)
                            .show();
                } else {
                    // TODO Code to run on unsuccessful
                    Toast.makeText(getContext(), "not root", 
Toast.LENGTH_LONG)
                            .show();
                }
            } catch (InterruptedException e) {
                // TODO Code to run in interrupted exception
                Toast.makeText(getContext(), "not root", Toast.LENGTH_LONG)
                        .show();
            }
        } catch (IOException e) {
            // TODO Code to run in input/output exception
            Toast.makeText(getContext(), "not root", 
Toast.LENGTH_LONG).show();
        }


On Saturday, August 25, 2012 1:44:55 AM UTC-7, RAJESH wrote:
>
> Hello all,
>
>
>      Can any one tel me how to check device is rooted or UN-Rooted from my 
> app ? 
>
>
> Thanks,
> Rajesh K
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to