0

In my apps (rooted devide), I want to chmod some files, folders to read and write. My code's here:

String path = "/mnt/sdcard/.android_secure";
String[] chmod = { "su", "-c","chmod 777 "+path };
try {
    Runtime.getRuntime().exec(chmod);
} catch (IOException e) {
    e.printStackTrace();
}

File f = new File("/mnt/sdcard/.android_secure");
f.canRead();

But the file still unreadable!

Jav_Rock
  • 22,059
  • 20
  • 123
  • 164
Brian Nguyen
  • 465
  • 1
  • 5
  • 15

2 Answers2

2

I suggest you to read the output of the command to check the error reported by the command and then take the required corrective action.

Process process = Runtime.getRuntime().exec(chmod); 
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));

String line;
while ((line = bufferedReader.readLine()) != null){

    Log.d("myTAG", line);
}

good luck

Luis
  • 11,978
  • 3
  • 27
  • 35
1

Usually sdcard is formated in fat filesystem. And this type of filesystem does not support unix style of file permissions. Can you use the same code for checking if you can change permissions for folders on device?

Yury
  • 20,618
  • 7
  • 58
  • 86