openUrl()
The function openUrl is used to open files located at arbitrary URLs in external applications.
Synopsis
int openUrl(string url);
Parameters
Parameter | Description |
---|---|
url |
The URL: a file or an address, e.g.: "/tmp/file.png" "file:///C:/Documents and Settings/All Users/Desktop" "http://www.x.org"; "mailto:test@some.org" CAUTION: On iOS only "mailto:" and "http:" or "https:" URLs are supported. |
Return value
If the function was successfully executed it returns 0 and in case of errors -1.
Description
The function openUrl is used to open files located at arbitrary URLs in external applications. For URLs that correspond to resources on the local file system (where the URL scheme is "file"), a suitable application is used to open the file; otherwise, a web browser is used to fetch and display the file.
On Android (on a non-rooted device), an application cannot access a file which was created by a different application in the apps cache folder. Thus, save the file under a system path to which all applications have access. Therefore, use the CTRL function getStandardPath(). For how to use the function, see example below.
Example
This example opens the image file "about.png":
main()
{
openUrl("C:/Temp/about.png");
}
The example opens an e-mail to the recipient test@some.org:
main()
{
openUrl("mailto:test@some.org");
}
This example opens the image "Image.jpg". The image is saved in the user directory of the current user/Downloads and the image is opened. The HTTP server listens to the port number 80.
main()
{
mapping m;
netGet("http://localhost:80/data/Bild.jpg",
m,makeMapping("target", getStandardPath("Download")));
openUrl(m["target"]);
}
This example opens the index.html page. The HTTP server listens to the port number 8080.
main()
{
openUrl("http://localhost:8080/data/index.html");
}
Assignment
HTTP functions
Availability
UI, CTRL