I need to set permissions for a file and its folder i are in both internal storage / data / folder in my The app can only do this:
string [] cmd = {"su", "-c", "chmod 777" + myakDB.getParentFile (). GetPath ()}; Process process = runtime.gettime (). Exec (CMD); Process.waitFor (); CMD = new string [] {"su", "-c", "6 6 6" + mac db.gatepath ()}; Process = runtime.gettime (). Exec (CMD); Process.waitFor ();
Thus he asks the superuser twice for permission. This is an unwanted behavior that I guess for my app's users. So finding the same problem on the Internet, I found the following solution (using the stream):
process process = runtime.gettime (). Exec ("su"); DataOutputStream Out = New DataOutputStream (process.getOutputStream ()); Out.writeBytes ("chmod 777" + myakDB.getParentFile (). GetPath ()); Out.Litebites ("chmod 666" + myakDB.getPath ()); Out.writeBytes ("Exit \ n"); Out.flush ();
But sometimes it does not work, nothing happens, and sometimes this superuser removes the query and then hangs on the white screen. So what's wrong in my process?
You must add a new line after each command:
Process process = runtime.gettime (). Exec ("su"); DataOutputStream Out = New DataOutputStream (process.getOutputStream ()); Out.writeBytes ("chmod 777" + myakDB.getParentFile (). GetPath () + "\ n"); Out Litebites ("6 6 6" + Mac DB Gate Path (+) "\ n"); Out.writeBytes ("Exit \ n"); Out.flush ();
Comments
Post a Comment