On Android, I'm am using a webview to display a chart designed by the API flot.
I'm using this code:
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.graphique);
// Get a reference to the declared WebView holder
WebView webview = (WebView) this.findViewById(R.id.webView1);
// Get the settings
WebSettings webSettings = webview.getSettings();
// Enable Javascript for interaction
webSettings.setJavaScriptEnabled(true);
// Make the zoom controls visible
//webSettings.setBuiltInZoomControls(true);
// Allow for touching selecting/deselecting data series
webview.requestFocusFromTouch();
// Set the client
webview.setWebViewClient(new WebViewClient());
webview.setWebChromeClient(new WebChromeClient());
webview.setBackgroundColor(0);
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
// Load the URL
webview.loadUrl("file:///android_asset/graph.html");
The graph is displayed correctly and fills the entire webview even if the width and height are not the same at start (thanks to setLoadWithOverviewMode(true) and setUseWideViewPort(true)).
But the user can still zoom and unzoom the graph by double tapping on it.
I want to prevent this action, I tried to put my webview to clickable=false, focusable=false and focusableintouchmode=false but it doesn't work.
I tried this also :
webview.getSettings().setBuiltInZoomControls(false);
But it doesn't work. Do you have any clue ?
try to set
webView.getSettings().setUseWideViewPort(false);
and deal with scale manually to fit the width..
Related
I load my ad banner page inside of app like
WebView reklam1goruntule = (WebView) findViewById(R.id.reklam1);
WebSettings webSettings = reklam1goruntule.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
reklam1goruntule.loadUrl("http://mywebside.com/adbanner.html");
reklam1goruntule.setWebViewClient(new WebViewClient());
I would like to use change this url any time using by firebase.And load to new url.So I'll use like..
myRef.child("Ads").child(mAuth.getCurrentUser().getUid()).child("Banners").setValue("Ad240url");
But how do ı need replace this ?
reklam1goruntule.loadUrl("http://mywebside.com/adbanner.html");
it's need to looks like
reklam1goruntule.loadUrl("Ad240url");
I have a problem with Android Web view.
The slider work fine with Apple but doesn't load on Android WebView.
Can anyone help? www.pgc-usa.net/ivynails
Thanks
I think I know. Web views in Android by default do not have JavaScript enabled. This is because there is someway it can do harm to the app. To enable it though it takes two lines
WebSettings webSettings = yourWebview.getSettings();
yourWebview.setJavaScriptEnabled(true);
You can also set it so that links that are clicked open in the web view. ( Otherwise they open in browser.) to add this you just add
yourWebview.setWebViewClient(new WebViewClient());
All that together will make it come to this:
WebView yourWebview = (WebView) findViewById(R.id.myWebview);
yourWebview.loadUrl("http://www.pgc-usa.net/ivynails");
WebSettings webSettings = yourWebviewgetSettings();
webSettings.setJavaScriptEnabled(true);
yourWebview.setWebViewClient(new WebViewClient());
You can find out more by visiting this page on the Android developer site by clicking this link.
I am trying to make an Android app display a website in a WebView, but only the website home page actually show content properly via the WebView, the other pages completely disregard the website styles and display content with a white background and blue default hyperlinks. I tested the same type of app on iOS and it works fine there. What can I do about it?
This is the method:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView myWebView = (WebView) findViewById(R.id.webView);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.setWebViewClient(new WebViewClient());
myWebView.loadUrl("http://www.awesomestories.com");
}
Settings should be set. Tricks Like this:
WebSettings settings = webview.getSettings();
settings.setBuiltInZoomControls(true);
settings.setPluginState(PluginState.ON);
settings.setJavaScriptEnabled(true);
settings.setSupportZoom(true);
If you have kept Single Column Setting in WebView remove it, it will work just perfect.
myWebView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
If you have not kept Single Column setting and still its not working, then check that you have enabled JavaScript or not, if not then enable it.
myWebView.getSettings().setJavaScriptEnabled(true);
Android WebView requires you to explicitly enable javascript.
Styles in the page may be loaded via javascript, and generally websites don't tend to work good without it, so enabling it is important and might solve your problem in addition to that.
myWebView.getSettings().setJavaScriptEnabled(true);
I have an application in which I'm passing this URL to WebView.
Facebook URL
But the WebView is not displaying the page correctly.
The default android browser is displaying the content correctly.
Code
WebSettings wsettings = webView.getSettings();
wsettings.setBuiltInZoomControls(false);
wsettings.setSupportZoom(false);
wsettings.setJavaScriptEnabled(true);
webView.setScrollbarFadingEnabled(false);
webView.setHorizontalScrollBarEnabled(true);
wsettings.setUseWideViewPort(true);
wsettings.setLoadWithOverviewMode(true);
wsettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
wsettings.setAppCacheEnabled(true);
wsettings.setAppCachePath("");
wsettings.setUserAgentString("AndroidWebView");
wsettings.setDatabaseEnabled(true);
wsettings.setDomStorageEnabled(true);
webView.clearCache(true);
Please see the below screen shot for reference.
I have found the solution for this by removing the below code.
wsettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
wsettings.setAppCacheEnabled(true);
wsettings.setAppCachePath("");
wsettings.setUserAgentString("AndroidWebView");
wsettings.setDatabaseEnabled(true);
wsettings.setDomStorageEnabled(true);
webView.clearCache(true);
Add this options in your WebView code:
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.getSettings().setUseWideViewPort(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
if (Build.VERSION.SDK_INT < 8) {
mWebView.getSettings().setPluginsEnabled(true);
} else {
mWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
}
In my case, Facebook works perfectly.
Regards
I have tried the following to fit the web page based on the device screen size. But after code the text fields and drop down buttons are not working. Can anyone help me?
WebView myWebView;
#SuppressWarnings("deprecation")
#SuppressLint("SetJavaScriptEnabled")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
myWebView.getSettings().setPluginState(PluginState.ON);
myWebView.loadUrl("http://m.immigrer.com/potentiel");
myWebView.setWebViewClient(new myWebViewClient());
}
The page you linked to is designed to fit the screen by default. You should try setting setUseWideViewPort(true) as that makes the WebView pay attention to the site's viewport meta tag. Also, the LayoutAlgorithm setting might be messing things up: try using LayoutAlgorithm.NORMAL.
Use downloadListener or use onPageStarted() and check if your webview ends with '.pdf'.(Assuming your URL, which contains a PDF is ending with '.pdf'. Else check any qualifier you are using in all your URLs where you expect a PDF to download, and then pass on that URL to AsyncTask to download.
Tested the link with the following settings:
WebSettings s = getSettings();
s.setBuiltInZoomControls(true);
s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
s.setUseWideViewPort(true);
s.setLoadWithOverviewMode(true);
s.setSavePassword(true);
s.setSaveFormData(true);
s.setJavaScriptEnabled(true);
s.setRenderPriority(RenderPriority.HIGH);
s.setPluginState(android.webkit.WebSettings.PluginState.ON_DEMAND);
// enable navigator.geolocation
s.setGeolocationEnabled(true);
s.setGeolocationDatabasePath("");
// enable Web Storage: localStorage, sessionStorage
s.setDomStorageEnabled(true);
I was able to use text fields and drop down buttons. Some settings are irrelevant but hey it works