Android Tutorial Open the browser with a specific web page

Opening the browser is very simple.
First you need to add a reference to the Phone library.
Then:
B4X:
    Dim p As PhoneIntents
    StartActivity(p.OpenBrowser("http://www.b4x.com"))

p.OpenBrowser returns an Intent object. Intents are like messages that are sent to the system which then acts based on the information stored in the intent.
StartActivity keyword can be used to open other internal activities or to send intents to the system.
 

karmacomposer

Member
Licensed User
Longtime User
Is the webview added yet? I certainly can add it in the designer.

I love building personal browsers. How would I create one for myself with basic4android?

Mike
 

karmacomposer

Member
Licensed User
Longtime User
Why does the following code not work at all?

======================================
Sub Globals
Dim Button1 As Button
Dim WebView1 As WebView
Dim EditText1 As EditText
Dim Button2 As Button
Dim Button3 As Button
Dim Button4 As Button
Dim Button5 As Button
Dim Button6 As Button
Dim Panel1 As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("web2")
WebView1.Initialize("WebView1")
EditText1.Initialize("EditText1")
End Sub

Sub ButtonGo_Click
WebView1.LoadUrl(EditText1.Text)
End Sub

Sub ButtonBack_Click
WebView1.Back
End Sub

Sub ButtonForward_Click
Webview1.Forward
End Sub
=======================================

I have a panel1 on the activity

On panel1, I have the following:

WebView1
EditText1
Button1-6

The filename of the layout is "web2"

I cannot get web pages to show. I do have internet and it works just fine everywhere else and on the tablet, but not in this code. So, what is wrong? Am I not calling something correctly?

Mike
 
Last edited:

danijel

Active Member
Licensed User
Longtime User
Hi Erel,

I have something like this in my WebView:

B4X:
HTMLString=""
HTMLString=HTMLString & "<html>"
HTMLString=HTMLString & "<body>"
HTMLString=HTMLString & "<a href=""http://www.example.com"">"
HTMLString=HTMLString & "Example"
HTMLString=HTMLString & "</a>"
HTMLString=HTMLString & "</body>"
HTMLString=HTMLString & "</html>"
WebView1.LoadHtml(HTMLString)

And I need to open external browser when user click on "Example"
Can u pass me few lines how to do that?

Thank you very much
 

merlin2049er

Well-Known Member
Licensed User
Longtime User
Hi, how do you handle p.openbrowser if it fails? ie. no http:// in the url?

StartActivity(p.OpenBrowser("http://"&EditTextclweb.text))

Because it crashes on me.
 

sultan87

Active Member
Licensed User
Longtime User
No need to use the Phone library to open the browser, you could use just an intent like this:
B4X:
Private i as Intent

i.Initialize(i.ACTION_VIEW, "http://" & EditTextclweb.text)

StartActivity(i)
hello,
when using your code asks what internet explore choose
we can do it on the internet explore default
best regards
 

incendio

Well-Known Member
Licensed User
Longtime User
Hi,

I tried this code on 2 phones, A & B.

On phone A, worked without problem.
On phone B didn't work. The browser didn't open.

Phone B has a browser installed, manually open a browser on phone B then input the address, was okay.

Any hint how to solve this?

Thanks in advance.


EDIT
I used this codes
B4X:
   Private i As Intent
i.Initialize(i.ACTION_VIEW,"https://www.example.com")
StartActivity(i)

Didn't work.

Change to this code
B4X:
   Dim p As PhoneIntents
StartActivity(p.OpenBrowser("https://www.example.com")

Worked fine.
 
Last edited:
Top