Jump to content
weabow

Deep links to open the app

Recommended Posts

Hi there,

 

I would like to open my app (windows, macos, ios, android & linux) clicking on a link (inside an email for example), and pass to the app a parameter which is inside the link.

 

Is it possible ?

 

Regards

Share this post


Link to post

On Windows, there is the concepts of file type associations, URL handlers, etc.

On Android, you must use intents.

MacOS and iOS also has intents, but I don't know if FMX support them?

Linux - not sure.

 

Share this post


Link to post

Thanks.

 

For Windows I know associations, but as I know, it needs to have a file. I've already implemented it and it runs fine with the file. But the need I have is to use a link, something like Zoom...

 

It's a good news to know that on MacOs it can run. On mobiles, I've been told that it can run too, but on Apple maybee there are restrictions ?

 

Linux is not in a hurry for me.

Share this post


Link to post
On 9/29/2023 at 7:51 PM, weabow said:

Thanks.

 

For Windows I know associations, but as I know, it needs to have a file. I've already implemented it and it runs fine with the file. But the need I have is to use a link, something like Zoom...

 

It's a good news to know that on MacOs it can run. On mobiles, I've been told that it can run too, but on Apple maybee there are restrictions ?

 

Linux is not in a hurry for me.

I think what you need is register a URL scheme for your app on Windows as follows:
 

procedure RegisterURLScheme(protocol: string);
var
  reg: TRegistry;
begin
  reg := TRegistry.Create;
  reg.RootKey := HKEY_CURRENT_USER;
  reg.OpenKey('Software\Classes\' + protocol, true);
  reg.WriteString('', 'URL:' + protocol);
  reg.WriteString('URL Protocol', '');
  reg.CloseKey;
  reg.OpenKey('Software\Classes\' + protocol + '\DefaultIcon', true);
  reg.WriteString('', ParamStr(0));
  reg.CloseKey;
  reg.OpenKey('Software\Classes\' + protocol + '\shell\open\command', true);
  reg.WriteString('', '"' + ParamStr(0) + '" "%1"');
  reg.CloseKey;
  reg.OpenKey('Software\Classes\' + protocol + '\shell', true);
  reg.WriteString('', 'open');
  reg.CloseKey;
  reg.Free;
end;

Above function register a protocol and set its app association  with the current program ( ParamStr(0) ). e.g. if you register with protocol 'myapp', then the URL will be like myapp://the-encoded-data-as-uri. Inside your app, call ParamStr(1) to get the parameters as URL form.
Note: this solution is specific for Windows platform.

Share this post


Link to post

If you want to avoid the Browser Popup..

 

URLAllowlist.reg

 

Windows Registry Editor Version 5.00

 

[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome\URLAllowlist]

"1"="myapp://*"

 

[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Edge\URLAllowlist]

"1"="myapp://*"

 

[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Mozilla\Firefox\WebsiteFilter\Exceptions]

"1"="myapp://*"

Share this post


Link to post

Registration of the url scheme will open your app, when such a link is being clicked (e.g. "myregisteredprotocol://this&is&url&data=whatever").

 

However, to receive and decode the url part, your application must implement the IURLEventHandler interface and add an event handler.

Send me a PM if you need code for that.

Edited by Alexander Halser

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×