直接上代码:

unit OpenViewUrl;interface // URLEncode is performed on the URL// so you need to format it   protocol://pathfunction OpenURL(const URL: string; const DisplayError: Boolean = False): Boolean;implementationuses 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.
View Code

更多相关文章

  1. android 从横屏到竖屏状态出现黑屏
  2. Android(安卓)之WebView
  3. android兼容2.2及以前版本的退出方法
  4. Android(安卓)(DiskLruCache)硬盘缓存代码实现
  5. Android获取状态栏的高度
  6. Android(安卓)init.rc文件解析过程详解(二)
  7. Android(安卓)Apk加固(安全专项)
  8. Android系统源代码情景分析:基础知识
  9. AndroidStudio快捷键设置2

随机推荐

  1. 在android中实现两张图片对比
  2. Android HttpURLConnection Accept-Encod
  3. Android 获取网络图片方法
  4. android 字符串转换成JSON对象
  5. Android开发:文本实现两端对齐
  6. ANDROID开发,如何更改android的project ta
  7. 在TextView上显示图片信息
  8. android 自定义返回按钮
  9. Android - Toast自定义显示时间,以及时长
  10. Android /system/build.prop 文件