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:
{ 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!
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). The replacement seems to be "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/
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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.