Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public class SaveFileRequest
- Object
- FileDialogRequest<SaveFileRequest>
- SaveFileRequest
Describes a native Save dialog for
com.codename1.ui.Display#showSaveDialog(SaveFileRequest, com.codename1.util.SuccessCallback).
The content is supplied either as an existing file (#sourceFile(String))
or written on demand (#content(SaveContent)), after the user has chosen
a location, format and options:
Display.getInstance().showSaveDialog(new SaveFileRequest()
.suggestedName("Report.pdf")
.addFilter(new FileTypeFilter("PDF").extensions("pdf").mimeTypes("application/pdf"))
.addFilter(new FileTypeFilter("Plain text").extensions("txt").mimeTypes("text/plain"))
.addOption(FileDialogOption.checkbox("charts", "Include charts", true))
.content((result, out) -> out.write(("Charts: " + result.getOptionValue("charts"))
.getBytes("UTF-8"))),
result -> {
if (result.getError() != null) {
ToastBar.showErrorMessage("Export failed");
}
});
On Android the user picks a document through the Storage Access Framework and the content is streamed into it; on iOS the content is written to a temporary file which the document picker then exports. Either way the application never needs a storage permission.
Constructors
public SaveFileRequest() |
Methods
public SaveFileRequest suggestedName(String name) | Sets the file name the dialog suggests, including its extension. |
public SaveFileRequest confirmOverwrite(boolean confirm) | Asks before replacing an existing file. |
public SaveFileRequest sourceFile(String path) | Saves a copy of an existing FileSystemStorage file. |
public SaveFileRequest content(SaveContent content) | Writes the content once the destination is known. |
public String getSuggestedName() | The suggested file name, or null. |
public boolean isConfirmOverwrite() | Whether replacing a file asks first. |
public String getSourceFile() | The file being copied, or null. |
public SaveContent getContent() | The content writer, or null. |
public void writeContent(FileDialogResult result, OutputStream out)
throws IOException | Writes this request’s content to a stream. |
Inherited fields
From FileDialogRequest
HINT_MAC_SHOWS_TAG_FIELD, HINT_MAC_CAN_CREATE_DIRECTORIES, HINT_MAC_SHOWS_HIDDEN_FILES, HINT_MAC_CAN_SELECT_HIDDEN_EXTENSION, HINT_MAC_TREATS_PACKAGES_AS_DIRECTORIES, HINT_IOS_SHOWS_FILE_EXTENSIONS, HINT_IOS_EXPORT_AS_MOVE, HINT_ANDROID_INITIAL_URI, HINT_ANDROID_PERSIST_PERMISSION, HINT_WIN_CLIENT_GUID, HINT_WIN_DEFAULT_FOLDER, HINT_DESKTOP_SHOW_HIDDEN
Inherited methods
Constructor details
SaveFileRequest
public SaveFileRequest()Method details
suggestedName
public SaveFileRequest suggestedName(String name)Parameters
nameString- the file name
Returns
confirmOverwrite
public SaveFileRequest confirmOverwrite(boolean confirm)Parameters
confirmboolean- false to replace silently
Returns
sourceFile
public SaveFileRequest sourceFile(String path)FileSystemStorage file.Parameters
pathString- the file to copy
Returns
content
public SaveFileRequest content(SaveContent content)#sourceFile(String).Parameters
contentSaveContent- the writer
Returns
getSuggestedName
public String getSuggestedName()Returns
isConfirmOverwrite
public boolean isConfirmOverwrite()Returns
getSourceFile
public String getSourceFile()Returns
getContent
public SaveContent getContent()Returns
writeContent
public void writeContent(FileDialogResult result, OutputStream out)
throws IOExceptionParameters
resultFileDialogResult- what the user chose
outOutputStream- the destination
Throws
IOException- if neither content nor a source file was set, or writing fails