Here is my coding
webView1.loadUrl("http://www.ppshein.com.mm/testimage.jpg");
What I want is I want to cache this image when image is completely loaded in webview. That's why it can be able to display when device is offline.
Add the next lines:
mWebView.getSettings().setAppCacheEnabled(true);
mWebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
you can open cacheMode.when your img downloaded,it will be in the/data/data/your packagename/cache the directories below
Related
I know this question has been asked so many time , but i didn't get any proper and satisfactory solution. I want to show the Pdf file in web view , which is coming from the url ,when i click on the URL , my pdf downloads. Currently i am usinghtml following code for showing pdf file in web view , but it is opening the html file. I am getting stuck in this since 4 hours.Kindly suggest me where i am doing wrong.
Thanks in advance.
mWebview.getSettings().setJavaScriptEnabled(true);
WebSettings settings = mWebview.getSettings();
settings.setDefaultTextEncodingName("utf-8");
mWebview.loadData(response, "application/pdf; charset=utf-8",null);
i have following response coming in following format :-
**%PDF-1.4%���5 0 obj<</E 74937/H [ 1453 173 ]/L 75330/Linearized 1/N 1/O 8/T 75180>>**
I want to show the Pdf file in web view
WebView does not have a PDF renderer.
Kindly suggest me where i am doing wrong.
You are attempting to load a PDF directly into a WebView. Use something else to render the PDF.
For show pdf in webview use Direct url:
https://docs.google.com/gview?embedded=true&url="PDF_FILE_URL"
Now load above url in webview.
mWebview.loadUrl("https://docs.google.com/gview?embedded=true&url="PDF_FILE_URL"");
Hi i have data that contains HTML image tag and some text. To display this content i am using webView by following approach:
String getProductDetailsTechSpec = "<img src="http://myhost.com/myimages/image.jpg"/></br>Here is the content of my article. Yada Yada. Etc. Etc."
getProductDetailsTechSpec.loadDataWithBaseURL("", getTechSpec,
"text/html", "UTF-8", "");
when device is connected to the wi-fi or mobile data, image is displying properly and when user turn off the wi-fi/Mobile data after some time image does not displaying(it works for few mins because webview get cached the image but after some time it doesn't) . But text is still is working. Please give me suggestion hot to get rid of this problem.
Thanks in advance.
The text is working because simply the webview is able to draw the HTML tags that you're writing even if there is no internet connection .. just like if your write that HTML to a text file and run in with the browser in your computer ..
But for the image the webview displays it from a URL which needs connection to display it
if your're looking for a way to cache the image , you might wanna check out that link
When I try to reload the titanium webview true webview.reload(), the view does not reload correctly. Instead if loading the page it gives me a page not found.
what i'm doing:
In Titanium i make use of webviews to display data. These webviews make use of HTML that is stored in the local filesystem that Titanium offers. The webview is called url is set by :
webview.setUrl( Ti.Filesystem.applicationDataDirectory.toString() + 'index.html');
This sets the proper url for the webview, it let's me see the correct html page. When I use webview.reload(), it seems lost... is there a way to reload the webview, or should i remove and then add the webview again?
Setting a URL for WebView the resource is usually loaded from the Resources folder.
So try to move all HTML files there (into Resources, same folder where app.js is located) and simply use.
webview.setUrl('index.html');
This has worked for me both on iOS and Android.
(There is an issue related to Android regarding WebView and setting its content by html property but this shouldn't matter here)
I want to get images from the web page and save them into the local storage. I can find all image URLs from the HTML, load that images from the server and save them. But I don't want to access to the server second time for the same information which is already in webview. So I want to know how I can load images from the webview?
You can set a WebView cache in a few steps. Take a look below.
WebView webView = (WebView) findViewById(R.id.your_webView_Id);
String cacheDir = getDir("your_WV_cache_dir", Context.MODE_PRIVATE).getAbsolutePath();
webView.getSettings().setAppCacheMaxSize(1024 * 1024 * 1); // 1 Mb cache limited size > webView.getSettings().setAppCachePath(cacheDir);
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); // This constant is important to you. This way you can load daa from cache, if it was already downloaded once.
You might take a look to th other possible values to the constant above at the WebView.WebSettings official documentation.
Let me know if it works.
I have a URL which I can load in webview. If I open the webview through browser it takes less time, but if I load the URL in webview it takes more time. Also if I have to reuse the same webview page with the same URL in another screen then I am unable to do that because if I use the same webview object in different screens then also it takes time to load the URL.
How do I make my webview to load a URL instantly?
You could use the YSlow or Google PageLoad plugins for your browser, to get specific tips on how to improve page load and speed up your page.
You could try a different cache mode: http://developer.android.com/reference/android/webkit/WebSettings.html#setCacheMode%28int%29
or, if the page doesn't change, just use loadDataWithBaseURL:
http://developer.android.com/reference/android/webkit/WebView.html#loadDataWithBaseURL%28java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String%29
By default, a WebView provides no browser-like widgets, does not
enable JavaScript and web page errors are ignored.
here i paste small part of code of zirco-browser
settings.setJavaScriptEnabled(Controller.getInstance().getPreferences().getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_JAVASCRIPT, true));
settings.setLoadsImagesAutomatically(Controller.getInstance().getPreferences().getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_IMAGES, true));
settings.setUseWideViewPort(Controller.getInstance().getPreferences().getBoolean(Constants.PREFERENCES_BROWSER_USE_WIDE_VIEWPORT, true));
settings.setLoadWithOverviewMode(Controller.getInstance().getPreferences().getBoolean(Constants.PREFERENCES_BROWSER_LOAD_WITH_OVERVIEW, false));
settings.setSaveFormData(Controller.getInstance().getPreferences().getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_FORM_DATA, true));
settings.setSavePassword(Controller.getInstance().getPreferences().getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_PASSWORDS, true));
settings.setDefaultZoom(ZoomDensity.valueOf(Controller.getInstance().getPreferences().getString(Constants.PREFERENCES_DEFAULT_ZOOM_LEVEL, ZoomDensity.MEDIUM.toString())));
settings.setUserAgentString(Controller.getInstance().getPreferences().getString(Constants.PREFERENCES_BROWSER_USER_AGENT, Constants.USER_AGENT_DEFAULT));
set render priority high for your web view can solve problem up to some extent
its some thing like this
webview.getSettings().setRenderPriority(RenderPriority.HIGH);