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.

相关阅读 >>

Delphi unicode转换ansi

Delphi unigui中cookies使用中文汉字的方法

Delphi 程序重新启动自身

Delphi清除ie临时文件,历史记录

Delphi+access错误"不正常地定义参数对象。提供了不一致或不完整的信息。"

Delphi 从listview组件中的选定行在数据库中删除

Delphi中用拼音首字符序列来实现检索功能

Delphi decodeutf8str解决系统自带utf8解码缺陷

Delphi tlist性能注意事项

Delphi读取radiogroup选中按钮的string文本

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...

    正在狠努力加载,请稍候...