(Uri uri)
| 1145 | } |
| 1146 | |
| 1147 | public boolean canWrite(Uri uri) { |
| 1148 | boolean canWrite = false; |
| 1149 | try { |
| 1150 | // if the file is not writable this throws a SecurityException |
| 1151 | OutputStream os = context |
| 1152 | .getContentResolver() |
| 1153 | .openOutputStream(uri, "wa"); |
| 1154 | |
| 1155 | if (os == null) return false; |
| 1156 | |
| 1157 | os.close(); // we don't actually want to write anything, so we close immediately |
| 1158 | canWrite = true; |
| 1159 | } catch ( |
| 1160 | SecurityException | IllegalArgumentException | IOException ignored |
| 1161 | ) { |
| 1162 | // if we don't have write-permission or the file doesn't exist, canWrite can stay on false |
| 1163 | } |
| 1164 | return canWrite; |
| 1165 | } |
| 1166 | } |
| 1167 | |
| 1168 | class MyFileObserver extends FileObserver { |
no test coverage detected