Dismiss Notice

REGISTRATION IS AFTER ADMIN ACTIVATION

DONATIONS WITH PAYPAL CLICK TO BUTTON

1 MONTH VIP - 5$; 3 MONTHS VIP - 10$; 6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$

DONATIONS WITH Bitcoin Address:3NRs3CK3fhXifrNYxHEZKpETDd9vNLMsMD

Dismiss Notice
The registration is approved by the Administrator. It takes about 1 day to approve your registration
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 Administrator 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

Laws
Our website, law, laws, copyright and aims to be respectful of individual rights. Our site, as defined in the law of 5651 serves as a provider of space. According to the law, contrary to the law of site management has no obligation to monitor content. Therefore, our site has adopted the principle of fit and remove. Works are subject to copyright laws and is shared in a manner that violated their legal rights, or professional associations, rights holders who, adsdelphi@gmail.com I can reach us at e-mail address. Complaints considered to be infringing on the examination of the content will be removed from our site.
Donate Help To Us and Be VIP
DONATIONS WITH PAYPAL CLICK TO BUTTON
6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$
Social Block