Get or create writable subdirectory for specified base directory @param dir is base directory @param subdir is subdirectory name, null to use base directory @param createIfNotExists is true to force directory creation @return writable directory, null if not exist or
(File dir, String subdir, boolean createIfNotExists, boolean writableOnly)
| 74 | * @return writable directory, null if not exist or not writable |
| 75 | */ |
| 76 | public static File getSubdir(File dir, String subdir, |
| 77 | boolean createIfNotExists, boolean writableOnly) { |
| 78 | if (dir == null) |
| 79 | return null; |
| 80 | File dataDir = dir; |
| 81 | if (subdir != null) { |
| 82 | dataDir = new File(dataDir, subdir); |
| 83 | if (!dataDir.isDirectory() && createIfNotExists) |
| 84 | dataDir.mkdir(); |
| 85 | } |
| 86 | if (dataDir.isDirectory() && (!writableOnly || dataDir.canWrite())) |
| 87 | return dataDir; |
| 88 | return null; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Returns array of writable data directories on external storage |