zoukankan      html  css  js  c++  java
  • Delphi XE5 android openurl(转)

    unit OpenViewUrl;
    interface // URLEncode is performed on the URL// so you need to format it   protocol://path
    function OpenURL(const URL: string; const DisplayError: Boolean = False): Boolean;
    implementation
    uses IdURI, SysUtils, Classes, FMX.Dialogs,
    {$IFDEF ANDROID}
      FMX.Helpers.Android, Androidapi.JNI.GraphicsContentViewText, Androidapi.JNI.Net, Androidapi.JNI.JavaTypes;
    {$ELSE}{$IFDEF IOS}iOSapi.Foundation, FMX.Helpers.iOS;
    {$ENDIF IOS}{$ENDIF ANDROID}
    
    function OpenURL(const URL: string; const DisplayError: Boolean = False): Boolean;
    {$IFDEF ANDROID}
    var Intent: JIntent;
    begin // There may be an issue with the geo: prefix and URLEncode.// will need to research
      Intent := TJIntent.JavaClass.init(TJIntent.JavaClass.ACTION_VIEW, TJnet_Uri.JavaClass.parse(StringToJString(TIdURI.URLEncode(URL))));
      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}
    end.
  • 相关阅读:
    nginx预防常见攻击
    nginx性能优化(针对于高并发量仅供参考,并不是方案)
    nginx平滑升级(1.14--1.15)
    LAMP动静分离安装(源码安装)
    洛谷-P1098 字符串的展开
    洛谷-P1086 花生采摘
    洛谷-P1042 乒乓球
    洛谷-P1031 均分纸牌
    洛谷-P1023 税收与补贴问题
    洛谷-P1125 笨小猴
  • 原文地址:https://www.cnblogs.com/china1/p/3415472.html
Copyright © 2011-2022 走看看