public OutputStream openForWrite(final Uri uri, final boolean append) {
        if (isEmpty(uri)) {
            return null;
        }

        try {
            //values "wa" (for append) and "rwt" (for overwrite) were tested on SDK21, SDK23, SDk29 and SDK30 using "ContentStorageTest"
            //Note that different values behave differently in different SDKs so be careful before changing them
            return context.getContentResolver().openOutputStream(uri, append ? "wa" : "rwt");
        } catch (IOException | SecurityException | IllegalArgumentException se) {
            //SecurityException is thrown for valid Uri which we have no permission to access
            //IllegalArgumentException is thrown for invalid Uri (e.g. because a folder/file was deleted meanwhile)
            reportProblem(R.string.contentstorage_err_write_failed, se, false, uri);
        }
        return null;
    }
Opens an Uri for writing. Remember to close stream after usage! Returns null if Uri can't be opened for writing.
main/src/main/java/cgeo/geocaching/storage/ContentStorage.java