Android Question [SOLVED] Webviev Alert Messages as Toaster

arifkibrit

Member
Licensed User
Hi, I made a website and then i want to use it as a APP so i made all but i couldn't show alert messages as toaster. Could you please help me about it ?
 

MicroDrie

Well-Known Member
Licensed User
Longtime User
Could you please help me about it ?
Yes do a search with the word "toast" and make you choice.
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
We all are willing to help you, however everyone expects that you show what you have done so far. Furthermore the IDE will show you the different options and sometimes even a short sub routine.
Of course all beginnings are difficult, but researching and certainly a lot of searching, reading and studying for the found examples of a search will help you to make very nice programs very quickly. Also take a moment to watch the many instructional videos.
And if you still struggle with applying a bit of routine flawlessly, put it between the code tag / at a specific question or do an export as zip file of your entire program.
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
To get an alert message from a webpage is quite tricky.
Essentially you have to send that message back to B4X which will then display the message on top of the webpage.
So you need a java bridge back to B4X. In B4A you need to use WebViewExtras, and this:

B4X:
'Private wvx As WebViewExtras
'Public wv As WebView
'
wvx.addJavascriptInterface(wv, "b4x")

'In Webpage HTML use this script to overide alert();

function alert(s){b4x.CallSub('scriptAlert', true, s);}

'In B4X
'This gets fired when function alert(s){b4x.CallSub('scriptAlert', true, s);} is executed in script
Private Sub scriptAlert(s As String)    'ignore
    xui.MsgboxAsync(s, "Alert")
End Sub

It is also possible in B4J, but more complicated.
 
Last edited:
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
To inject the overriding alert function into an existing HTML in B4A:

B4X:
    Dim js As String = "function alert(s){b4x.CallSub('scriptAlert', true, s);}"
    Dim xjs As String = "javascript: " & js
    wvx.executeJavascript(wv, xjs)
 
Upvote 0

arifkibrit

Member
Licensed User
Thank you so much this worked for me :)
To get an alert message from a webpage is quite tricky.
Essentially you have to send that message back to B4X which will then display the message on top of the webpage.
So you need a java bridge back to B4X. In B4A you need to use WebViewExtras, and this:

B4X:
'Private wvx As WebViewExtras
'Public wv As WebView
'
wvx.addJavascriptInterface(wv, "b4x")

'In Webpage HTML use this script to overide alert();

function alert(s){b4x.CallSub('scriptAlert', true, s);}

'In B4X
'This gets fired when function alert(s){b4x.CallSub('scriptAlert', true, s);} is executed in script
Private Sub scriptAlert(s As String)    'ignore
    xui.MsgboxAsync(s, "Alert")
End Sub

It is also possible in B4J, but more complicated.
 
Upvote 0
Top