-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathuOpenViewUrl.pas
47 lines (41 loc) · 1.37 KB
/
uOpenViewUrl.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
unit uOpenViewUrl;
{ from:
https://stackoverflow.com/questions/7443264/how-to-open-an-url-with-the-default-browser-with-firemonkey-cross-platform-appli/7453797
https://www.developpeur-pascal.fr/p/_2000-ouvrir-un-site-web-dans-le-navigateur-par-defaut-depuis-une-application-firemonkey.html
}
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes,
System.Variants,
{$IF Defined(IOS)}
macapi.helpers, iOSapi.Foundation, FMX.helpers.iOS;
{$ELSEIF Defined(ANDROID)}
Androidapi.JNI.GraphicsContentViewText, Androidapi.JNI.Net, Androidapi.JNI.App, Androidapi.helpers;
{$ELSEIF Defined(MACOS) OR Defined(LINUX64)}
Posix.Stdlib;
{$ELSEIF Defined(MSWINDOWS)}
Winapi.ShellAPI, Winapi.Windows;
{$ENDIF}
procedure OpenURL(const URL: string);
implementation
procedure OpenURL(const URL: string);
{$IF Defined(ANDROID)}
var
Intent: JIntent;
{$ENDIF}
begin
{$IF Defined(ANDROID)}
Intent := TJIntent.Create;
Intent.setAction(TJIntent.JavaClass.ACTION_VIEW);
Intent.setData(StrToJURI(URL));
tandroidhelper.Activity.startActivity(Intent);
// SharedActivity.startActivity(Intent);
{$ELSEIF Defined(MSWINDOWS)}
ShellExecute(0, 'OPEN', PWideChar(URL), nil, nil, SW_SHOWNORMAL);
{$ELSEIF Defined(IOS)}
SharedApplication.OpenURL(StrToNSUrl(URL));
{$ELSEIF Defined(MACOS) OR Defined(LINUX64)}
_system(PAnsiChar('open ' + AnsiString(URL)));
{$ENDIF}
end;
end.