giving root access to android application
<p>I'm building an application that has to take a super user permission to write in the /data directory modify the content of database file. i write some code for getting root access but it is giving me in log Can't "get root access or denied by user"</p>

<p>my code is </p>

<pre><code>@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if(canRunRootCommands())
            Toast.makeText(this, "Can Run Root Commands", Toast.LENGTH_LONG).show();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

     public static boolean canRunRootCommands()
       {
          boolean retval = false;
          Process suProcess;

          try
          {
             suProcess = Runtime.getRuntime().exec("su");

             DataOutputStream os = new DataOutputStream(suProcess.getOutputStream());
             DataInputStream osRes = new DataInputStream(suProcess.getInputStream());

             if (null != os &amp;&amp; null != osRes)
             {
                // Getting the id of the current user to check if this is root
                os.writeBytes("id\n");
                os.flush();

                String currUid = osRes.readLine();
                boolean exitSu = false;
                if (null == currUid)
                {
                   retval = false;
                   exitSu = false;
                   Log.d("ROOT", "Can't get root access or denied by user");
                }
                else if (true == currUid.contains("uid=0"))
                {
                   retval = true;
                   exitSu = true;
                   Log.d("ROOT", "Root access granted");
                }
                else
                {
                   retval = false;
                   exitSu = true;
                   Log.d("ROOT", "Root access rejected: " + currUid);
                }

                if (exitSu)
                {
                   os.writeBytes("exit\n");
                   os.flush();
                }
             }
          }
          catch (Exception e)
          {
             // Can't get root !
             // Probably broken pipe exception on trying to write to output stream (os) after su failed, meaning that the device is not rooted

             retval = false;
             Log.d("ROOT", "Root access rejected [" + e.getClass().getName() + "] : " + e.getMessage());
          }

          return retval;
       }
</code></pre>

<p>how to get root access to a so that i can update the database file??</p>
