1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Donation with Paypal!!!

    Go to your paypal account and send directly donation to [email protected]

    1 month - 10 $ - Standart VIP

    6 months - 20 $- Standart VIP

    1 year - 30 $- Standart VIP

    2 years - 50 $- Standart VIP

    Gold member for life - 150 $- Standart VIP

    High Vip (Standart VIP include) group please send PM or email to [email protected] for info

    After Donation please send email to [email protected]

  3. Donation Ways 2020


    Paysend
  4. Telegram
Dismiss Notice

Donation with Paypal!!!

Go to your paypal account and send directly donation to [email protected]

1 month - 10 $ - Standart VIP

6 months - 20 $- Standart VIP

1 year - 30 $- Standart VIP

2 years - 50 $- Standart VIP

Gold member for life - 150 $- Standart VIP

High Vip (Standart VIP include) group please send PM or email to [email protected] for info

After Donation please send email to [email protected]

Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Execute or open a file with Delphi on all platforms

Discussion in 'Delphi Programming' started by AdminDF, Apr 3, 2014.

  1. AdminDF
    Online

    AdminDFAdminDF is a Verified Member Delphifan Staff Member DF Staff

    Platform:Delphi XE5 Update 2

    Only a function to open file in Windows,Android,Ios….

    Windows –> shellExecute
    Android –> sending an intent to SO
    Ios –> using NSUrl

    Code:
    uses … IdGlobalProtocols,{$IFDEF MSWINDOWS},WinFolderSelectUtils {$ENDIF}
      {$IFDEF MSWINDOWS },WinAPI.ShellApi,WinAPI.Windows {$ENDIF}
    {$IFDEF ANDROID}
     ,FMX.Helpers.Android,Androidapi.JNI.GraphicsContentViewText,
     Androidapi.JNI.Net,Androidapi.JNI.JavaTypes,idUri,Androidapi.IOUtils
    {$ENDIF ANDROID}
    {$IFDEF IOS}
     ,iOSapi.Foundation,FMX.Helpers.iOS
    {$ENDIF IOS};
     
     
    function OpenURLorFile(URL:string;const DisplayError:Boolean = False):Boolean;
    {$IFDEF MSWINDOWS}
    begin
     ShellExecute(0,‘OPEN’,PChar(URL),”,”,SW_SHOWNORMAL);
    end;
     
     
    {$ELSE}
    {$IFDEF ANDROID}
    var
     Intent:JIntent;
     idMimeTable:TIdMimeTable;
    begin
    // There may be an issue with the geo:prefix and URLEncode.
    // will need to research
     if URl.toLower.StartsWith(‘http://’) then
      Begin
       Intent:= TJIntent.JavaClass.init(TJIntent.JavaClass.ACTION_VIEW,
       TJnet_Uri.JavaClass.parse(StringToJString(TIdURI.URLEncode(URL))));
      End
     Else
      Begin
       try
        idMimeTable:= TidMimeTable.Create;
        Intent:= TJIntent.Create;
        Intent.setAction(TJIntent.JavaClass.ACTION_VIEW);
        if not url.ToLower.StartsWith(‘file://’) then
         url:= ‘file://’ + url;
        Intent.setDataAndType(StrToJURI(Url), StringToJString(idMimeTable.GetFileMIMEType(Url)));
     
       Finally
        try idMimeTable.Free;except end;
       End;
     
     
      End;
     try
      SharedActivity.startActivity(Intent);
      exit(true);
     except
      on e:Exception do
      begin
       if DisplayError then ShowMessage(‘Error:‘ + e.Message);
       exit(false);
      end;
     end;
    end;
    {$ELSE}
    {$IFDEF IOS}
    var
     NSU:NSUrl;
    begin
     // iOS doesn’t like spaces,so URL encode is important.
     NSU:= StrToNSUrl(TIdURI.URLEncode(URL));
     if SharedApplication.canOpenURL(NSU) then
      exit(SharedApplication.openUrl(NSU))
     else
     begin
      if DisplayError then
       ShowMessage(‘Error:Opening "’ + URL + ‘"not supported.’);
      exit(false);
     end;
    end;
    {$ELSE}
    begin
     raise Exception.Create(‘Not supported!’);
    end;
    {$ENDIF IOS}
    {$ENDIF ANDROID}
    {$ENDIF WINDOWS}
     
     
  2. atek2013
    Offline

    atek2013 Guest

    thank you
     
  3. ana21675
    Offline

    ana21675 DF Member

    wahhh manteb
     

Share This Page