Sending a URL to Another App on Android and iOS with Delphi XE5

Here is the source code for my Open and View URL library from my CodeRage 8 session “Beyond the App”. Here is a download of the example app. I’ll see about posting it to a SVN repository too so it can grow and evolve. Thanks to Al Mannarino for his code that started this!

Note the code is using TidURL.URLEncode on all URLs. I found it is only required on the maps for iOS (iOS doesn’t like spaces) but may be causing trouble with the geo:// on Android.

Some example protocols

  • http, tel, sms, fb, mailto, twitter, geo, etc.

Example URLs

  • – Common to both iOS & Android –
  • tel://(415)834-3131
  • sms://1234
  • (This opens with the Twitter client on Android)
  • mailto://
  • twitter://user?screen_name=coderage
  • fb://profile/34960937498 (get the UID from or for whatever page you are looking for)
  • – iOS Specific –
  • Scotts Valley Drive, Scotts Valley, CA 95066 (this needs the URL encode – Apple has some additional APIs that are recommended.)
  • – Android Only –
  • content://contacts/people/
  • content://contacts/people/1
  • geo://0,0?q=5617 Scotts Valley Drive, Scotts Valley, CA 95066
  • geo://46.191200, -122.194400 (I think this one doesn’t like the URLEncode)
unit OpenViewUrl;


// URLEncode is performed on the URL
// so you need to format it   protocol://path
function OpenURL(const URL: string; const DisplayError: Boolean = False): Boolean;


  IdURI, SysUtils, Classes, FMX.Dialogs,
  FMX.Helpers.Android, Androidapi.JNI.GraphicsContentViewText,
  Androidapi.JNI.Net, Androidapi.JNI.JavaTypes;
  Macapi.Helpers, iOSapi.Foundation, FMX.Helpers.iOS;

function OpenURL(const URL: string; const DisplayError: Boolean = False): Boolean;
  Intent: JIntent;
// There may be an issue with the geo: prefix and URLEncode.
// will need to research
  Intent := TJIntent.JavaClass.init(TJIntent.JavaClass.ACTION_VIEW,
    on e: Exception do
      if DisplayError then ShowMessage('Error: ' + e.Message);
  NSU: NSUrl;
  // iOS doesn't like spaces, so URL encode is important.
  NSU := StrToNSUrl(TIdURI.URLEncode(URL));
  if SharedApplication.canOpenURL(NSU) then
    if DisplayError then
      ShowMessage('Error: Opening "' + URL + '" not supported.');
  raise Exception.Create('Not supported!');

This entry was posted in Android, Conferences, iOS, Mobile. Bookmark the permalink.

25 Responses to Sending a URL to Another App on Android and iOS with Delphi XE5

  1. Hi!
    Thank you so much for sharing your code, very useful!
    Maybe you can help me?
    In an Android system, I need to open a web page, login, navigate in order to find something and after that, send the actual url at my app.
    I can’t use a TwebBrowser because seem impossible enable the keyboard for the edit field (damn login!!)

  2. Pingback: Open URLs On Android And IOS With Delphi XE5 Firemonkey | Delphi Firemonkey, Delphi Android, Delphi IOS

  3. Jim McKeeth says:

    Maybe if the login is a post method you could login, but not sure about the navigating.

  4. Abhinav Sanghvi says:

    How can we play a song URL in delphi XE5 with help of Media Player component or Web Browser component, but without redirecting on any default browser,
    Is there any path to localize the URL

  5. Pingback: Liens de l’épisode 11 de la saison 3 | Le Dev du Jeudi

  6. In XE6, they moved the helpers from what is included. You need to add Androidapi.Helpers and Macapi.Helpers to the list of uses.

  7. Mario says:

    thanks for sharing, it works great with website etc but when using the mailto, somewhere it remove teverything before and uincuding the @ of the mailto email address, had anyone else had this happen?

    I use the function like this
    if not OpenURL(‘mailto://’, true) then

  8. Jim McKeeth says:

    Try removing URLencode.

  9. elia says:

    this is very good, but for insert a attachment when send mail how i do?

  10. Jim McKeeth says:

    This code wouldn’t support that, but you can probably figure out a way to do that.

  11. mca64 says:

    hi, on XE7 i have
    [DCC Error] OpenViewUrl.pas(31): E2003 Undeclared identifier: ‘StringToJString’
    [DCC Error] OpenViewUrl.pas(33): E2003 Undeclared identifier: ‘SharedActivity’

    Thanks for help

  12. mca64 says:

    nevermid, added Androidapi.Helpers to list of uses

  13. mca64 says:

    omg its workin! Thank you very much 🙂

  14. leonard says:

    I want to open the app WhatsApp. Is it possible?

  15. Jim McKeeth says:

    Perhaps. You would need to see if WhatsApp publishes a URL prefix that you can use to call to it. If it does then you totally can.

  16. How can I open an PDF file using this functions?

  17. Jim McKeeth says:

    If the PDF is online, then you can use the fully HTTP URL to open it. If it is local, then you need to save it in a common file folder (not in your app folder) and then use the file:// prefix on the fully qualified PDF file name and path. Sarina had a blog post about another way to open it on Android:

  18. Pingback: Delphi Android: Activity? - Delphi-PRAXiS

  19. Can i open my app when user click a link in twitter? thats mean, example : i post a twitt and has a link.i want user open my app when click the this link of course if my app installed. otherwise go to store.

  20. Thanks for the unit.
    It works fine as designed to. except for mailto:// protocol (in Android)
    In my case it opens the mail app but the without the email mentioned in the url.

  21. Remi says:

    To fix it for mail on Android you only should put “mailto:” in front of the email address and change code to:

    Intent := TJIntent.JavaClass.init(TJIntent.JavaClass.ACTION_VIEW,

  22. hebrao says:

    To open Whatsapp, use a URL like:


  23. Baris says:

    Hello, how can i share a web address with facebook app. facebook://share?u= … ??

  24. Daniele says:

    Hello I can’t send a message with whatsapp with IOS, can you tell me the instruction to call back?

  25. John says:

    If I use the code below I get the following error – “Host field is empty”

    sPath : String;
    sPath := TPath.Combine(TPath.GetPublicPath, ‘test1.pdf’);
    if FileExists(sPath) = true then
    end else
    Showmessage(‘file does not exist! ‘ + sPath);


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.