I try to display the full content of a web page into a WebView. The text is displayed correctly but the images not. I've searched tons of posts but none of them helped me. This is what I have tried:
webView = myFragment.findViewById(R.id.web_view);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setUseWideViewPort(true);
webSettings.setDomStorageEnabled(true);
webSettings.setAppCacheEnabled(true);
webSettings.setLoadsImagesAutomatically(true);
webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
webView.loadUrl(URL);
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
public void onPageFinished(WebView view, String url) {
progressBar.setVisibility(View.GONE);
}
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Log.d(TAG, "Error: " + description);
}
});
The URL that I'm passing to the loadUrl() function looks like this:
mydomain.com/category/category_name/
I have also tried:
mydomain.com/category/category_name/index.php
But it doesn't display the images, only the text. How to solve ths?
Any help will be appreciated, thank you!
try this
webSettings.setJavaScriptEnabled(true);
webSettings.setBlockNetworkImage(false);
Related
In my WebView, a particular url is not . Apart from this url, all urls are working. Please tell me what's the problem.
webView = findViewById(R.id.web_game);
webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient());
webView.clearCache(true);
webView.clearHistory();
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.loadUrl("https://cobra-game.conversionlab.online/");
Add a listener to ignore the SSL errors as given below, You must be receiving some SSL errors while loading the URL.
webView.setWebViewClient(new WebViewClient() {
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Log.d("Failure Url :" , failingUrl);
}
#Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
Log.d("Ssl Error:",handler.toString() + "error:" + error);
handler.proceed();
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
And add this as well
webView.getSettings().setDomStorageEnabled(true);
I am using webview for showing Flipkart website in my application.
Everything is working fine as needed except one thing:
when I click on BuyNow button, select variant view gets visible.
This view comes for 1 sec and then show the white blank page.
Is there any setting i need to enable in webview to show this types of view?
I had already gone through many questions on Stackoverflow but nothing helped me.
I tried setting webchromeclient and below methods on webview with no success.
shopping_webview.getSettings().setAllowFileAccess(true);
shopping_webview.getSettings().setAllowContentAccess(true);
shopping_webview.getSettings().setAllowFileAccessFromFileURLs(true);
shopping_webview.getSettings().setAllowUniversalAccessFromFileURLs(true);
shopping_webview.getSettings().setDomStorageEnabled(true);
shopping_webview.getSettings().setUseWideViewPort(true);
shopping_webview.getSettings().setLoadWithOverviewMode(true);
shopping_webview.getSettings().setLoadsImagesAutomatically(true);
shopping_webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
shopping_webview.getSettings().setSupportMultipleWindows(true);
shopping_webview.getSettings().setBuiltInZoomControls(true);
shopping_webview.getSettings().setDisplayZoomControls(false);
shopping_webview.getSettings().setJavaScriptEnabled(true);
webviewLink.getSettings().setLoadsImagesAutomatically(true);
webviewLink.getSettings().setJavaScriptEnabled(true);
webviewLink.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webviewLink.loadUrl(postlink);
webviewLink.setWebViewClient(new WebViewClient() {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO show you progress image
progressBar.setVisibility(View.VISIBLE);
super.onPageStarted(view, url, favicon);
}
#Override
public void onPageFinished(WebView view, String url) {
// TODO hide your progress image
progressBar.setVisibility(View.GONE);
super.onPageFinished(view, url);
}
});
load the Url with this way it's work for me in the same app..
WebView webView = (WebView) findViewById(R.id.webView);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
webView.setWebViewClient(new MyWebViewClient());
webView.loadUrl(_URL);
}
private class MyWebViewClient extends WebViewClient{
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(getApplicationContext(), "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
}
My website has login control. If the user has logged in a different text, If the user has not logged in a different text.
I want to print on the screen.
Here is the code
WebView mWebView = (WebView) findViewById(R.id.Wview);
assert mWebView != null;
mWebView.getSettings().setJavaScriptEnabled(true);
WebSettings webSettings = mWebView.getSettings();
webSettings.setDefaultTextEncodingName("utf-8");
webSettings.setAllowFileAccess(true);
mWebView.loadUrl("http://arkadasimabakarmisin.com/");
mWebView.setWebViewClient(new WebViewClient() {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon)
{
view.loadUrl("javascript:document.getElementsByClassName(\"page-wrapper\")[0].setAttribute(\"style\",\"display:none;\"); " );
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
//
view.loadUrl("javascript:document.getElementsByClassName(\"page-wrapper\")[0].setAttribute(\"style\",\"display:none;\"); " );
}
});
I want open this link (http://e-sign-poc.s3-website-us-west-2.amazonaws.com/) like mobile browser using webview
mWebview = (WebView) findViewById(R.id.wb_sample);
WebSettings webSettings = mWebview.getSettings(); webSettings.setJavaScriptEnabled(true);
mWebview.setWebChromeClient(new WebChromeClient());
mWebview.setWebViewClient(new WebViewClient());
mWebview.loadUrl("http://e-sign-poc.s3-website-us-west-2.amazonaws.com/");
This link not loading properly in webview, but this link works perfectly in telegram webview
Wait for some time after you load URL to WebView
It will work perfectly in my device
or
Try with this code
url = "http://e-sign-poc.s3-website-us-west-2.amazonaws.com/" +
"";
linearLayout.setVisibility(View.GONE);
webView.setVisibility(View.VISIBLE);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.loadUrl(url);
Try with it -
webView = (WebView) findViewById(R.id.wvTest);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR);
webView.setWebViewClient(new WebViewClient(){
#Override
public void onLoadResource(WebView view, String url) {
super.onLoadResource(view, url);
progressBar.setProgress(view.getProgress());
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
progressBar.setVisibility(View.VISIBLE);
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progressBar.setVisibility(View.GONE);
}
});
webView.loadUrl("https://www.example.com");
I have a simple webview ,nothing complex
URL = getIntent().getExtras().getString(FinalVariables.LOAD_URL);
mWebView =(WebView) findViewById(R.id.mywebview);
progressBar = (ProgressBar)findViewById(R.id.progressbar);
if(!TextUtils.isEmpty(URL))
mWebView.loadUrl(URL);
mWebView.setWebViewClient(new WebViewClient() {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
progressBar.setVisibility(View.VISIBLE);
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return super.shouldOverrideUrlLoading(view, url);
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progressBar.setVisibility(View.GONE);
}
});
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
But for some reason if the opened page has a video in it, it won't get played
this is what I am seeing now.But when I run this same code on sony device,no problems there.I tried enabling the android:hardwareAccelerated="true" in AndroidManifest.xml but didn't work.Any help is appreciated.
I found a solution for this and was quite simple.Adding a single line on shouldOverrideUrlLoading fixed the problem ie,
mWebView.setWebChromeClient(new WebChromeClient());
Hope this will help someone.