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.
Related
I am trying to load the cached version of the website when mobile internet is off. But I am only getting a white screen.
Here is my code.
binding.webView.getSettings().setJavaScriptEnabled(true);
binding.webView.getSettings().setDomStorageEnabled(true);
binding.webView.getSettings().setAppCacheEnabled(true);
binding.webView.getSettings().setAllowFileAccess(true);
binding.webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
binding.webView.getSettings().setAppCachePath(getApplicationContext().getCacheDir().getAbsolutePath());
if (!isNetworkAvailable()) {
binding.webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ONLY);
}
binding.webView.setWebChromeClient(new WebChromeClient());
binding.webView.setWebViewClient(new WebViewClient() {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
binding.progressBar.setVisibility(View.VISIBLE);
}
#Override
public void onPageFinished(WebView view, String url) {
binding.progressBar.setVisibility(View.GONE);
binding.webView.setVisibility(View.VISIBLE);
}
});
binding.webView.loadUrl("website url here");
Try changing this line:
binding.webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
To:
binding.webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
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.
I have a PHP service that returns me HTML that I display in a WebView using
activity_news_complete_webview.loadDataWithBaseURL("", html, "text/html", "UTF-8", null);
Also implemented the WebViewClient as follows
WebViewClient webViewClient = new WebViewClient() {
#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);
}
#SuppressWarnings("deprecation")
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
#TargetApi(Build.VERSION_CODES.N)
#Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
view.loadUrl(request.getUrl().toString());
return true;
}
#Override
public void onLoadResource(WebView view, String url) {
super.onLoadResource(view, url);
}
};
In doing so when i tap on any , the WebViewClient shows that the url attribute is about:blank but the tag contain proper urla in html variable which i load in the WebView.
Any one who can suggest me a proper solution for this would be a great help, I have read many threads on this issue but haven't found any proper solution because anything i try gives the same issue.
You can use this line replace to .loadDataWithBaseURL();
activity_news_complete_webview.loadData(html, "text/html; charset=utf-8", "UTF-8");
Its working perfectly for me. try this one.
Using webview.loadUrl(url) method I open an url. If I click any Button on the view it directs to another page. Now I want to get the url of the directed page. how can I get it?
I also want the content that is displayed on the webview. How to get the content of the WebView ?
String webUrl = webView.getUrl();
please see my answer
may it will help you...!!!!
WebView webview = new WebView(context);
webview.setWebViewClient(new WebViewClient()
{
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
Log.d("WebView", "your current url when webpage loading.." + url);
}
#Override
public void onPageFinished(WebView view, String url) {
Log.d("WebView", "your current url when webpage loading.. finish" + url);
super.onPageFinished(view, url);
}
#Override
public void onLoadResource(WebView view, String url) {
// TODO Auto-generated method stub
super.onLoadResource(view, url);
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
System.out.println("when you click on any interlink on webview that time you got url :-" + url);
return super.shouldOverrideUrlLoading(view, url);
}
});
I am assuming that you have set your WebViewClient.If not then you can do like below,
webView.setWebViewClient(new MyWebViewClient());
String currentUrl;
private class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
currentUrl=url;
return true;
}
}
Here when you click on any link on the WebView then it will call shouldOverrideUrlLoading() and you can get the current url there in currentUrl.
this is the most simple way of handling this for API > 20: There are obviously other methods with parsers like HTMLCleaner to have more control. However, this is good and simple for getting URL. Each time URL changes in Webview, URL in the request object changes as well.
#Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
String temp = request.getUrl().toString();
if(temp.isEmpty()){
Log.i(ActivityName, "No url returned!");
}else{
Log.i(ActivityName, temp);
}
return false;
}
you can also make your call by overriding onpagefinished method of webviewclient. I wanted to note this, since this is called when page finishes loading.
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);
}
}