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) -> report.export(result.getSelectedFilter(),
"true".equals(result.getOptionValue("charts")), out)),
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 methods
Constructor details
SaveFileRequest
public SaveFileRequest()Method details
suggestedName
public SaveFileRequest suggestedName(String name)Sets the file name the dialog suggests, including its extension.
Parameters
nameString- the file name
Returns
this request
confirmOverwrite
public SaveFileRequest confirmOverwrite(boolean confirm)Asks before replacing an existing file. On by default; the mobile
pickers always handle conflicts their own way.
Parameters
confirmboolean- false to replace silently
Returns
this request
sourceFile
public SaveFileRequest sourceFile(String path)Saves a copy of an existing
FileSystemStorage file.Parameters
pathString- the file to copy
Returns
this request
content
public SaveFileRequest content(SaveContent content)Writes the content once the destination is known. Takes precedence
over
#sourceFile(String).Parameters
contentSaveContent- the writer
Returns
this request
getSuggestedName
public String getSuggestedName()The suggested file name, or null.
Returns
the name
isConfirmOverwrite
public boolean isConfirmOverwrite()Whether replacing a file asks first.
Returns
true to confirm
getSourceFile
public String getSourceFile()The file being copied, or null.
Returns
the path
getContent
public SaveContent getContent()The content writer, or null.
Returns
the writer
writeContent
public void writeContent(FileDialogResult result, OutputStream out)
throws IOExceptionWrites this request’s content to a stream. Ports call it once the user
has chosen a destination; the stream is not closed here.
Parameters
resultFileDialogResult- what the user chose
outOutputStream- the destination
Throws
IOException- if neither content nor a source file was set, or writing fails