Shell commands are not part of the SDK. What you are doing can't be relied upon to work.
And it looks like you are trying to use the "su" command, which is guaranteed to not work on a regular user build. On Wed, Feb 16, 2011 at 10:22 PM, maikelalonso <[email protected]>wrote: > Hi: > > I'm trying to change file permissions with chmod from code using > runtime.getRuntime(). The problem is it runs ok in my smartphone > (Samsung GT-I5700) but in other devices (Motorola Cliq) it runs ok in > a few times and in other times it not change the permissions. Any > idea? Thanks. > > Here is my code: > > //Coypy program1 to app folder > > is = getAssets().open("program1"); > fos = new > FileOutputStream(getDir("", MODE_WORLD_WRITEABLE)+"/ > program1"); > tmp = new byte[1024]; > > while ((l = is.read(tmp)) != -1) { > fos.write(tmp, 0, l); > fos.flush(); > } > > fos.close(); > is.close(); > > //Coypy script.sh to app folder > > is = getAssets().open("script.sh"); > fos = new > FileOutputStream(getDir("", MODE_WORLD_WRITEABLE)+"/ > script.sh"); > tmp = new byte[1024]; > > while ((l = is.read(tmp)) != -1) { > fos.write(tmp, 0, l); > fos.flush(); > } > > fos.close(); > is.close(); > > //Set permissions rwxrwxrwx to program1 > commands = new String[] {"chmod","777", > getDir("", > MODE_WORLD_WRITEABLE)+"/program1"}; > Process process = > Runtime.getRuntime().exec("su"); > StringBuffer res = new StringBuffer(); > DataOutputStream os = new > DataOutputStream(process.getOutputStream()); > DataInputStream osRes = new > DataInputStream(new > > BufferedInputStream(process.getInputStream(),8192)); > for (String single : commands) { > os.writeBytes(single + " "); > os.flush(); > } > os.writeBytes("exit\n"); > os.flush(); > os.close(); > process.waitFor(); > osRes.close(); > try { process.destroy(); } catch > (Exception e) { /* nothing > */ } > > //Set permissions rwxrwxrwx to > script.sh > commands = new String[] > {"chmod","777", getDir("", > MODE_WORLD_WRITEABLE)+"/script.sh"}; > process = > Runtime.getRuntime().exec("su"); > res = new StringBuffer(); > os = new > DataOutputStream(process.getOutputStream()); > osRes = new DataInputStream(new > > BufferedInputStream(process.getInputStream(),8192)); > for (String single : commands) { > os.writeBytes(single + " > "); > os.flush(); > } > os.writeBytes("exit\n"); > os.flush(); > os.close(); > process.waitFor(); > osRes.close(); > try { process.destroy(); } > catch (Exception e) { /* nothing > */ } > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- Dianne Hackborn Android framework engineer [email protected] Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

