[英]Open URL in XE6 firemonkey IOS-DELPHI
Good Morning, 早上好,
I'm trying to do a cross-platform application for both android and IOS to open a URL that will pass as parameter in the default browser in android I have achieved using the following code: 我正在尝试为android和IOS做一个跨平台的应用程序,以打开一个URL,该URL将作为参数在android默认浏览器中传递,我已经使用以下代码实现了:
{ Intent := TJIntent.JavaClass.init(TJIntent.JavaClass.ACTION_VIEW,
TJnet_Uri.JavaClass.parse(StringToJString
('http://www.***.com'));
SharedActivity.startActivity(Intent); }
But in IOS do not know how to open a URL in the default browser, I searched thousands of pages that use methods but none have helped me, if you could help me I would greatly appreciate it! 但是在IOS中,我不知道如何在默认浏览器中打开URL,我搜索了数千个使用方法的页面,但没有一个对我有帮助,如果可以的话,我将不胜感激!
Here is the happy path for what I did (excluding error handling, etc.) 这是我所做的事情的理想路径(不包括错误处理等)
uses
//...
IdURI,
{$IFDEF ANDROID}
Androidapi.Helpers, FMX.Helpers.Android, Androidapi.JNI.GraphicsContentViewText,
Androidapi.JNI.App, Androidapi.JNI.Net, Androidapi.JNI.JavaTypes
{$ENDIF ANDROID}
{$IFDEF MSWINDOWS}
Winapi.ShellAPI, Winapi.Windows
{$ENDIF MSWINDOWS}
{$IFDEF IOS}
Macapi.Helpers, iOSapi.Foundation, FMX.Helpers.iOS
{$ENDIF IOS}
;
and 和
//...
procedure TForm1.launchBrowser();
var
myURL: string;
{$IFDEF ANDROID}
Intent: JIntent;
{$ENDIF ANDROID}
{$IFDEF IOS}
NSU: NSUrl;
{$ENDIF IOS}
begin
myURL := 'http://www.example.com';
{$IFDEF MSWINDOWS}
ShellExecute(0, 'OPEN', PChar(myURL), '', '', SW_SHOWNORMAL);
{$ENDIF MSWINDOWS}
{$IFDEF IOS}
NSU := StrToNSUrl(TIdURI.URLEncode(myURL));
if SharedApplication.canOpenURL(NSU) then
begin
SharedApplication.openUrl(NSU);
end;
{$ENDIF IOS}
{$IFDEF ANDROID}
Intent := TJIntent.Create;
Intent.setAction(TJIntent.JavaClass.ACTION_VIEW);
Intent.setData(StrToJURI(myURL));
TAndroidHelper.Activity.startActivity(Intent);
{$ENDIF ANDROID}
end;
Note: "SharedActivity" has been deprecated (at least in 10/Seatle). 注意:不建议使用“ SharedActivity”(至少在10 / Seatle中)。 The replacement seems to be "TAndroidHelper.Activity"
替换似乎是“ TAndroidHelper.Activity”
I think you should do it that way. 我认为您应该那样做。 Works perfect for me:
对我来说很完美:
http://delphi.org/2013/10/sending-a-url-to-another-app-on-android-and-ios-with-delphi-xe5/ http://delphi.org/2013/10/sending-a-url-to-another-app-on-android-and-ios-with-delphi-xe5/
uses Androidapi.Helpers;
procedure TForm1.SpeedButton1Click(Sender: TObject);
var Intent: JIntent;
begin
Intent := TJIntent.Create;
Intent.setAction(TJIntent.JavaClass.ACTION_VIEW);
Intent.setData(StrToJURI('http://www.website.com.br/index.php'));
SharedActivity.startActivity(Intent);
end;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.