Date: 2017jan19
OS: Android
Keywords: directory
Q. How can I make a file or folder world readable?
A. At or after OS Level 9 use setReadable:
boolean makeWorldReadable(final String filename) {
File f = new File(filename);
return f.setReadable(true, false);
}
Before OS Level 9, use chmod:
boolean chmod(final String file, final int mode) {
final String strMode = String.format("%o", mode);
boolean result = false;
try {
Process p = Runtime.getRuntime().exec("chmod " + strMode + " " + file);
result = true;
} catch (IOException e) {
result = false;
}
return result;
}
Example use for a file:
chmod("myfile.txt", 0666);
Example use for a folder:
chmod("myfolder", 0777);