Local Html Page become blank after several load - android

I just suffered from a case that some local html file will become blank page after reload/ being ignored for some period of time. However, the html file will works fine again in a new tab.
It is remarkable that the page contains no Javascript.
Besides, it is also reported that the same set of local html will become blank page rarely and randomly when loading in Android Webview. The permission configuration and folder path (using:file:/// as the beginning of the url) are both valid and exists in the machine. The Webview has set clearcache to true before each loading.
I have also checked the page that, all the page elements are still there but they cannot be displayed.
It is remarkable that, reload the webpage will never work.
Here is the capture of the page after it become blank page.
Any idea?
EDIT 1
source code of Android loading the local html file
WebView wv = new WebView(this);
wv.setPadding(40, 40, 0, 0);
wv.setWebChromeClient(new MyWebChromeClient());
wv.clearCache(true);
WebSettings webSettings = wv.getSettings();
webSettings.setTextSize(WebSettings.TextSize.NORMAL);
webSettings.setJavaScriptEnabled(true);
webSettings.setUseWideViewPort(true);
webSettings.setSupportZoom(true);
webSettings.setBuiltInZoomControls(true);
File ext = Environment.getExternalStorageDirectory();
String filePath = ext.toString() + "/some_folder/";
wv.loadUrl("file:///" + filePath + "HTML Forms/form1.html");
vh.webLinearLayout.addView(wv,
new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));

Related

Style property not working in webview

I am loading html pages from assets and showing in application. HTML pages are showing but when I tried to change background color of button on "onclick" then background color is not getting change.
If i test pages with browser then it's working but when I load html pages in android using webview then it's not working.
onclick function getting called but somehow style property not getting applied.
I tried following three ways.
1. $('#btnAC').css({'background-image', 'linear-gradient(180deg, black, red) !important'});
2. document.getElementById("btnAC").style = "background-image: linear-gradient(180deg, black, red) !important;";
3. $('#btnAC').css('background-image', 'linear-gradient(180deg, black, red) !important');
Java code :
WebView webView = (WebView) findViewById(R.id.webView);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.loadUrl("http:///android_asset/Web/index.html");
You could use WebView.loadDataWithBaseURL
htmlData = "" + htmlData;
// lets assume we have /assets/style.css file
webView.loadDataWithBaseURL("file:///android_asset/", htmlData, "text/html", "UTF-8", null);*

Android Webview doesn't load

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.

How to display a pdf in a web browser without any possibility of saving, printing or sharing

I need to show a pdf file in an android app, so that the users will not be able to save or share it, nor Google will keep a copy of it.
I have thought of using iframes, but this allows the users to open the pdf file in a browser (and print or share it from there).
Here is what I came up with:
pdfView.setWebChromeClient(new WebChromeClient());
WebSettings settings = pdfView.getSettings();
settings.setPluginState(WebSettings.PluginState.ON);
pdfView.setWebViewClient(new WebViewClient());
pdfView.setBackgroundColor(0x00000000);
settings.setAllowFileAccess(false);
settings.setBuiltInZoomControls(true);
settings.setSupportZoom(true);
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(false);
settings.setSaveFormData(false);
settings.setJavaScriptEnabled(true);
String html = "<iframe src=\"http://docs.google.com/gview?url=" +
path + "&embedded=true&wmode=opaque\"" +
"style=\"width:600px; height:900px;\" scrolling=\"no\"" +
"frameborder=\"0\" allowfullscreen></iframe>";
pdfView.loadDataWithBaseURL(null, html, "text/html", "UTF-8", null);
The solution does not have to be based on embedding and showing in a web browser.
I need to support API 16+, so using PdfRenderer is not an option.
It helped me to add sandbox="allow-same-origin allow-scripts" inside the iframe tag.

how to load pdf file in a webview from assets folder

I ahve a webview in my layout screen. I need to display a PDF file in that webview from my assets folder. I tried below code. While running app displays zoom in and out controls with a blank page(our PDF file is kind of large.is it due to that?).
webView = (WebView) findViewById(R.id.webView1);
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.JELLY_BEAN) //required for running javascript on android 4.1 or later
{
settings.setAllowFileAccessFromFileURLs(true);
settings.setAllowUniversalAccessFromFileURLs(true);
}
settings.setBuiltInZoomControls(true);
webView.setWebChromeClient(new WebChromeClient());
webView.loadUrl("file:///android_asset/test.pdf");
I dont want to use external apps to read my PDF. is it possible?then how?
You can use pdf.js from Mozilla to display a PDF in a webview inside an Android application.
Here is the solution...
https://stackoverflow.com/a/21383356/2260073
This question is answered already . For the details refer the following links.
How to read pdf in my android application?.
One more is
stackoverflow.com/questions/10299839/how-to-read-pdf-in-my-android-application/10352422#10352422
After searching a lot about this i came up with my own kind of solution
I used this website to convert my PDF to DOCX and then DOCX to HTML using online converters and then used the following code to load the HTML in my Webview.
String htmlString = "<p>YOUR HTML CODE</p>";
webView.loadData(htmlString, "text/html", "UTF-8");
Hope this helps!

read local pdf through webview

I am doing one application to read pdf from sdcard through webview. I used the following code.
webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new HelloWebViewClient());
File file = new File(Environment.getExternalStorageDirectory()
+ "/MotoronAug.pdf");
Uri uri = Uri.fromFile(file);
webview.loadUrl(uri.toString());
but i got a blank page. But when i give a web address
webview.loadUrl("http://docs.google.com/viewer?url=http%3A%2F%2Fresearch.google.com%2Farchive%2Fbigtable-osdi06.pdf");
I can read it from webview what is the problem in my code?...I have MotoronAug.pdf file in my sdcard.Help me friends
Online or local both wont be rendered by webview.

Categories

Resources