Help / WLanguage / WLanguage functions / Mobile specific functions / URI functions
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WindowsLinuxPHPWEBDEV - Browser code
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Stored procedures
Saves, in the background, the content of a resource (image, text, etc.) identified by its URI in an external file.
AndroidAndroid Widget
// Open the system window to select a pdf
UriResource is URI = URISelect("application/pdf")
IF NOT ErrorOccurred THEN
	// Save the resource in the application directory
	URIToFile(UriResource, "document.pdf", ProcSave)
	INTERNAL PROCEDURE ProcSave (bResult, sPath)
		IF bResult THEN
			ToastDisplay("Saved successfully")
			ToastDisplay("Unable to save")
AndroidAndroid Widget
// Save a resource with conversion 
UriResource is URI = URISelect()
IF NOT ErrorOccurred THEN
	// Retrieves the MIME type into which the resource can be converted
	sMIMEType is string = URIGetInfo (UriResource, uriInfoConversionType)
	IF sMIMEType <> "" THEN
		// If there are several possible MIME types
		IF StringCount(sMIMEType, CR) > 1 THEN
			// Ask the user to choose the type to use
		// Save the resource on the device
		URIToFile(UriResource, SysDirExternalStorage(1, sseAppDocument), ...
					ProcEndSave, sMIMEType)
		INTERNAL PROCEDURE ProcEndSave (bResult, sResourcePath)
			IF bResult THEN
				ToastDisplay(StringBuild("File saved (%1)", ...
URIToFile(<URI> , <Path> , <Procedure> [, <MIME type>])
<URI>: URI or character string variable
URI or character string variable that identifies the resource to save.
<Path>: Character string
Corresponds to:
  • a directory path (this directory must exist): the resource will be saved in this directory. The name of the created file will correspond to the original name of the resource, and its extension will depend on the format used to save it (see notes).
  • A full or relative file path. If the file already exists, it will be overwritten.
    Caution: the file extension will not be modified even if the resource had to be converted to another format to be saved.
The full path of the saved file will be passed as a parameter of the procedure called once the save has been completed.
<Procedure>: Name of the WLanguage procedure
Name of the WLanguage procedure ("callback") called once the save has been completed. This procedure has the following format:
PROCEDURE <Procedure name> (<Result>, <Path>)
  • <Result> is boolean:
    • True if the save has been completed,
    • False otherwise. To get more details on the error, use ErrorInfo before any other call to a WLanguage function (this would reinitialize the error).
  • <Path> is a character string that corresponds to the full file path used for saving.
<MIME type>: Optional character string
MIME type corresponding to the format in which the resource must be saved (see Notes).
If this parameter is not specified or corresponds to an empty string (""), the resource will be saved in its original format if possible or it will first be converted to a default format.
  • To select a resource and get its URI, use URISelect.
  • When the resource to save does not come from the device's file system, the content provider that manages the resource may need to convert this resource. This is usually the case if no application on the device can manage the original format of the resource. It is possible to specify the conversion format of the resource by entering the parameter <MIME type>. To find out the MIME type into which a resource can be converted, use URIGetInfo with the constant uriInfoConversionType. If this function returns an empty string (""), the resource cannot be saved. In this case, do not call URIToFile on this resource, since it will fail.
    a Microsoft Word file (.doc or.docx) is selected using URISelect. This file is on Google Drive and no application on the device can handle this type of document. When saving this resource, the content provider will automatically convert this resource to PDF format. In this case, URIGetInfo used with the constant uriInfoConversionType will return the following string: "application/pdf + TAB + .pdf".
Component: wd300android.aar
Minimum version required
  • Version 24
Click [Add] to post a comment

Last update: 06/28/2024

Send a report | Local help