I have made a simple android webview app. Everything is working fine only my progressbar (loader) not showing when app opened. Rest of the pages when user navigate to another link then progressbar showing.
MainActivity.java file
webview.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
...
}
#Override
public void onPageStarted(WebView view, String url) {
super.onPageStarted(view, url);
progressBar.setVisibility(View.VISIBLE);
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progressBar.setVisibility(View.GONE);
}
});
My problem is onPageStarted method. When I remove this then every page navigation display progressbar (except first time when app opened) but once I place onPageStarted method as above then android studio display an error like
method does not override method from its superclass
I am new in android and apology for this question if it is violet any policy. Need help.
Your onPageStarted() override method do not have all the required parameters of parents class. It should be as shown below
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
Related
I can't open mht files in WebView.
It worked fine until Chrome v76, but v77 had a read error
If chrome is returned to v76, the read was successful.
file: /// also didn't work.
Loading with loadDataWithBaseURL also didn't work
webview.loadUrl("file://{$context.cacheDir}/file.mht")
cid: Frame- "Random string" # mhtml.blink
Net :: ERR_UNKNOWN_URL_SHCEME
Sorry for my late answer because i face same problem and i was searching solution yesterday and i resolve it today like below.
In your java class you have to give below code
webView.setWebViewClient(new WebViewClient() {
#Override
public void onLoadResource(WebView view, String url) {
super.onLoadResource(view, url);
if (one_time==1)//one_time is only a variable because i want
// to run view.loadUrl(url); only one time.
view.loadUrl(url);
one_time++;
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return true;
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
#Override
public void onPageFinished(WebView view, final String url) {
}
});
I think you are giving
view.loadUrl(url);
in below method
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// view.loadUrl(url); like this
// you will need this when you will load the url but in case
//of mht page it will not work
return true;
}
do not do this if you are loading mht page because
shouldOverrideUrlLoading(WebView view, String url){...}
loads the url and it also run when first time you open webview activity.
so,
onLoadResource(WebView view, String url){...}
method load the Resource.
Trying to load this website with WebView, but it just show a blank page.
I can open other website with no problem, but not the above website. Possible the web developer block it? The website is not owned by me.
guideView = (WebView) findViewById(R.id.guideView);
guideView.setWebViewClient(new myWebClient());
guideView.getSettings().setJavaScriptEnabled(true);
guideView.loadUrl("https://sapsnkra.moe.gov.my/ibubapa2/index.php");
}
public class myWebClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
#Override
public void onPageStarted(WebView view, String url,
Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
}
I tried to setWebChromeClient, but it do not work as well.
This link is apparently is blocked to access. I tried to access and dont work.
Make sure this .php is working to network access. As it is a .gov url there may be blocks.
I know how to get notified when it finishes loading a web page, but is there any way to know when it starts loading a new one that is initiated from a link from the original web page?
The reason that i want it is to make a ProgressBar visible whenever a page starts loading, and make it invisible whenever it finishes.
UPDATE: What I'm asking is if it's possible to know when a new page starts loading a page. Although from the link I found onPageStarted, and it works.
Check with the following
webView.setWebViewClient(new WebViewClient() {
//If you will not use this method url links are opeen in new brower not in webview
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
public void onLoadResource (WebView view, String url) {
//Show loader on url load
}
public void onPageFinished(WebView view, String url) {
//cancel loader complted
}
});
// Set Javascript enabled on webview
webView.getSettings().setJavaScriptEnabled(true);
To listen for a web page starting loading you should override onPageStarted, to listen for finishing you should override onPageFinished
and just to make it more complete, listen for error with onReceivedError
webView.setWebViewClient(new WebViewClient() {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon){
super.onPageStarted(view, url, favicon);
// runs when a page starts loading
progressBar.setVisibility(View.VISIBLE);
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
// page finishes loading
progressBar.setVisibility(View.GONE);
}
#Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
// runs when there's a failure in loading page
progressBar.setVisibility(View.GONE);
Toast.makeText(context, "Failure on loading web page", Toast.LENGTH_SHORT).show();
}
});
I am working with android app for the web view. It loads the webpage but i cant make more actions on the page using my app. when I am choosing a hyperlink from the page it shows a popup"complete the action using chrome,opera etc.." how can I use this without such browsers..I nedd to browse web contents using my app. how it possible??
I used the code
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://www.google.com");
please help me since I am new to android and thank you.
wv.loadUrl(url);
wv.setWebViewClient(new MyWebViewClient());
Your WebViewCLient class would look like this:
class MyWebViewClient extends WebViewClient {
#Override
// show the web page in webview but not in web browser
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
webProg.setVisibility(View.GONE);
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
#Override
public void onLoadResource(WebView view, String url) {
super.onLoadResource(view, url);
}
}
We have a requirement where we want multiple webview instance to be open from same application.
E.g Android app1 should open page1.html in first webview instance and page2.html in second webview instance. When page2.html is started page1.html webview should go in background.
Is this possible in Android? Is yes, Can you please provide sample code or link which talks in details as how this requirement can be achieved.
public void callwebtwo(){
loadweb = (WebView) findViewById(R.id.loadweb);
loadweb2 = (WebView) findViewById(R.id.loadweb2);
loadweb2.getSettings().setJavaScriptEnabled(true);
loadweb.getSettings().setJavaScriptEnabled(true);
loadweb2.loadUrl("http://www.google.co.in/");
loadweb.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.i("shouldOverrideUrlLoading", url.toString());
return super.shouldOverrideUrlLoading(view, url);
}
#Override
public void onPageFinished(WebView view, String url) {
Log.i("onPageFinished", url.toString());
super.onPageFinished(view, url);
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
Log.i("onPageStarted", url.toString());
super.onPageStarted(view, url, favicon);
}
}
});
loadweb2.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.i("shouldOverrideUrlLoading", url.toString());
return super.shouldOverrideUrlLoading(view, url);
}
#Override
public void onPageFinished(WebView view, String url) {
Log.i("onPageFinished", url.toString());
super.onPageFinished(view, url);
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
Log.i("onPageStarted", url.toString());
super.onPageStarted(view, url, favicon);
}
});
}
instance of the both web is different so it will work and perform seperatly..
i gvn ans whtever i cn understand frm ur quest.
Yes you can do it in android.
Create seperate activities for both and when you load page2 in second webview instance then obvisouly page1 webview instance will be in back of second and when you press back from page2 then page1 will be infront.