iOS Question B4A to B4I simple code conversion

francesco paolo lavecchia

Member
Licensed User
Hi everyone,

I need to convert this code:

Sub Globals
Dim wv As WebView
End Sub

Sub Activity_Create(FirstTime As Boolean)
wv.Initialize("wv")
wv.LoadUrl("http://www.mysite.net/")
End Sub

Sub wv_OverrideUrl (Url As String) As Boolean
Dim Intent1 As Intent

Sub wv_OverrideUrl (Url As String) As Boolean

Dim Intent1 As Intent

Intent1.Initialize(Intent1.ACTION_VIEW, Url)
Intent1.SetComponent("android/com.android.internal.app.ResolverActivity")
StartActivity(Intent1)

If Url.StartsWith("https://maps.google.it/?") Then
wv.Back
wv.Forward
Else If Url.StartsWith("https://www.google.com/maps/dir//") Then
wv.Back
wv.Forward
wv.Forward
End If

End Sub

thanks in advance to anyone who helps me....
 
Last edited:

francesco paolo lavecchia

Member
Licensed User
I tried so many ways and it doesn't work.

I mean, the ovverride function works only for the first time

Private Sub Application_Start (Nav As NavigationController)
NavControl = Nav
Page1.Initialize("Page")
Page1.RootPanel.LoadLayout("main")
NavControl.ShowPage(Page1)
wv.LoadUrl("http://www.mysite.com")
End Sub

Sub wv_OverrideUrl (Url As String) As Boolean
App.OpenURL(Url)
End Sub

After the firstApp.OpenURL(Url) excecution, the override function doent's work anymore
In android app the override function works always.


what should I do to solve the problem?
 
Upvote 0

karld

Active Member
Licensed User
Longtime User
I am far from an expert as I am still learning myself.

Someone else please correct me if I am wrong.....

Does it give any errors?
I am not sure what you are trying to do here. More code would be helpful.
What is calling the App..OpenURL subroutine?
 
Upvote 0

francesco paolo lavecchia

Member
Licensed User
B4A
B4X:
Sub Globals
Dim wv As WebView
End Sub

Sub Activity_Create(FirstTime As Boolean)
wv.Initialize("wv")
wv.LoadUrl("http://www.mysite.net/")
End Sub

Sub wv_OverrideUrl (Url As String) As Boolean
Dim Intent1 As Intent

Sub wv_OverrideUrl (Url As String) As Boolean

Dim Intent1 As Intent

Intent1.Initialize(Intent1.ACTION_VIEW, Url)
Intent1.SetComponent("android/com.android.internal.app.ResolverActivity")
StartActivity(Intent1) 

If Url.StartsWith("https://maps.google.it/?") Then
wv.Back
wv.Forward
Else If Url.StartsWith("https://www.google.com/maps/dir//") Then
wv.Back
wv.Forward 
wv.Forward 
End If
End Sub

B4I
B4X:
Private Sub Application_Start (Nav As NavigationController)
NavControl = Nav
Page1.Initialize("Page")
Page1.RootPanel.LoadLayout("main")
NavControl.ShowPage(Page1)
wv.LoadUrl("http://www.mysite.com")
End Sub

Sub wv_OverrideUrl (Url As String) As Boolean
App.OpenURL(Url)
End Sub

After the first App.OpenURL(Url) excecution, the override function doent's work anymore
In android app the override function works always.

what should I do to solve the problem?
 
Upvote 0

francesco paolo lavecchia

Member
Licensed User
I tried but it doesn't work the same.
Could you send me a complete working example (zip)?
I need something that run the Google Maps app while users click on the relative link

MAPS.jpg
 
Last edited:
Upvote 0

francesco paolo lavecchia

Member
Licensed User
ok, but this code

B4X:
Private Sub Application_Start (Nav AsNavigationController)

NavControl = Nav
Page1.Initialize("Page")
Page1.RootPanel.LoadLayout("main")
NavControl.ShowPage(Page1)
wv.LoadUrl("http://www.mysite.com")

End Sub

Sub wv_OverrideUrl (Url AsString) As Boolean

App.OpenURL(Url)
Return True

End Sub


it's wrong... what should I do to solve this issue?

I need something that works like in android

B4X:
Sub Activity_Create(FirstTime As Boolean)

wv.Initialize("wv")
wv.LoadUrl("http://www.mysite.net/")

End Sub

Sub wv_OverrideUrl (Url AsString) As Boolean

Dim Intent1 As Intent
Intent1.Initialize(Intent1.ACTION_VIEW, Url)
Intent1.SetComponent("android/com.android.internal.app.ResolverActivity")
StartActivity(Intent1)

End Sub
 
Upvote 0

francesco paolo lavecchia

Member
Licensed User
My english is not so good to explain what I need... but I want to try
By default, when a user clicks on a link where there is a connection with google maps, the browser opens itself using a plug-in that allow it to open a map. Instead of this feature, I always want to open the google maps app...
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Here:
B4X:
#QueriesSchemes: comgooglemapsurl
#ATSEnabled: false
Sub Process_Globals
   Public App As Application
   Public NavControl As NavigationController
   Private Page1 As Page

   Private WebView1 As WebView
End Sub

Private Sub Application_Start (Nav As NavigationController)
   'SetDebugAutoFlushLogs(True) 'Uncomment if program crashes before all logs are printed.
   NavControl = Nav
   Page1.Initialize("Page1")
   Page1.Title = "Page 1"
   Page1.RootPanel.LoadLayout("1")
   NavControl.ShowPage(Page1)
   WebView1.LoadUrl("http://www.guidedocartis.it/marche/?page_id=17827")
End Sub

Sub WebView1_OverrideUrl (Url As String) As Boolean
   If Url.StartsWith("https://maps.google") Then
     Dim fixed As String = Url.Replace("https://", "comgooglemapsurl://")
     If App.CanOpenURL(fixed) Then
       App.OpenURL(fixed)
       Return True
     End If
   End If
   Return False
End Sub
 
Upvote 0
Top