Android Question How can I send Ctrl+F5 to Webview or AdvancedWebview ?

Adamdam

Active Member
Licensed User
Longtime User
Dear all,
Greetings,
How can I send Ctrl+F5 to Webview or AdvancedWebview ? to refresh loading css files.
That my App view website (I modified there css file) and now need to reload this website (in normal browser that occurred by pressing Ctrl+F5 )
now how can I force Webview or AdvancedWebview to re-load this website and reload css files.
Any help, please
Best regards
 

drgottjr

Expert
Licensed User
Longtime User
i strongly suspect you are not telling us everything here. if all you want to do is (re)load a webpage, you only need to
call webview.loadurl( "https://www.foo.bar" ). worst case, there is a chance the server serves a cached copy (ie, unmodified)
of the page, but this is unlikely. in any case, there are ways to deal with this.

i'm guessing (i have to guess because you do not say how you are modifying the source) that the server is on the
internet and that you make changes to the source and upload them while your android app with the webview is running.
you then want to reload the page while the app is running to see how the modifications are rendered. you could, of course, simply
launch the app again... anyway, if i'm incorrect, then stop reading here, and i apologize for wasting your time.

the easiest, cleanest way to handle this is to add a button to your activity. your webview presumably occupies the entirety of your
device screen. after adding the addview, you add a button to the activity at the bottom of the screen. have it say, eg,
"tap to refresh". after making your changes and uploading them to the server, tap the button to reload the page.

the button's code would be something like this:

B4X:
sub button_click
   webview.loadurl( "https://www.foo.bar" )
end sub

if you want to see what's going on, you should add this to your code:

B4X:
sub webview_pagefinished( url as string )
   log("finished loading: " & url)
end sub

that way you'll see the log message every time the page is loaded.

---------------------------------------------------------------------------------------------------------------------------------------------------
unless you have a specialized android device, perhaps you noticed that your android does not have a ctrl + F5 key
combination. you may have noticed that your device probably doesn't have a keyboard that's active all the time like
on your pc. so there are a number of problems involved in trying to carry out what you are asking to do.

out of the box, a webview knows nothing about ctrl + F5. in all likelihood, your pc's browser looks for ctrl + F5 and
causes the webpage to refresh. this is similar to the button approach suggested above. in other words, the webview
engine used by your pc's browser is not involved.

if you insist on using a keystroke, you will have to have a way of keeping android's soft keyboard available all the time
(which, of course, is going to interfere with the webview). if not available all the time, you'll have to have a way of making
visible and invisible at will. this will require another button (which will have to be visible when the keyboard is displayed
in order to hide the keyboard). this will require the ime library.

furthermore, in order to make your webview aware of keystrokes, you will have to inject javascript into the page with a
"magic" key that causes the page to reload when you touch it. this will require webviewextras or similar. the only tricky
part with this is the document itself must have the focus. if some other element of the page has the focus and you hit
the "magic" key, you'll be in for a surprise. but i'll assume you basically trying to devise a way of testing how your css
changes turned out. in any case, this approach is not particularly difficult, but it's overkill for what you're trying to achieve.
-------------------------------------------------------------------------------------------------------------------------------------------------------
another option would be to trap the "back" hard key on your device. tapping the "back" key will cause the page to
refresh. similar to the button, but without the button. you just need to make sure you know how to get out constantly
refreshing the page when you're actually trying to exit the app...
----------------------------------------------------------------------------------------------------------------------------------------------------------
i vote for the "tap to refresh" button.
 
Upvote 0
Top