Slovenian characters in webview - android

So i have a webview in which i want to display some html ... If i load html from web like this:
wv.loadUrl("http://www.somepage.com/somehtml.html");
It shows all characters like it should. Then i downloaded that code and save it to assets folder, now it laods but it doesn't show characters like š,ž,č correctly. I load it like that
wv.loadUrl("file:///android_asset/samehtml.html");
In the head of html i have set charset to utf-8. Start of my html looks like thease...
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="1138.32">
</head>

Related

The mobile chrome browser native share button copies only the url without query string when using Router from NextJS

I looked into this solution history.pushState does not update url for "share ..." button on mobile Chrome.
I tried this snippet,
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="canonical" href="http://localhost:3000">
<title>Test Website</title>
<script src="./jquery.min.js"></script>
</head>
<body>
Hey shan <br> <br>
<button id="btn">Click me</button>
<script>
$(document).ready(function () {
$('#btn').click(function () {
history.pushState({urlPath:'/'}, "/", "/1234?name=shan&color=87878");
});
});
</script>
</body>
</html>
This is working even without changing canonical url too. With the above code if i click the native share button in android chrome browser the string http://localhost:3000/1234?name=shan&color=87878 gets copied.
But in my actual website the same is not happening. The only change over there is Router.replace from nextjs. The approximate snippet looks like this
buttonClick = Router.replace(...)
The problem is when user clicks a button Router.replace is called with the params and everything works except the native share copies only the url http://localhost:3000/1234 not the query string.
But the querystring gets copied when i use the copy button or edit button on the browser.
I am not sure how to approach this problem, what could be the issue? Is any meta tag could block copying the queryparam?

How to inject CSS before show WebView?

I need some help on how to inject CSS before showing WebView. Appreciate any help.
I need to inject CSS into WebView from assets, before the WebView shows.
You should load url contents manually to your html structure. put this code as page.html in your assets folder.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<style type="text/css">
// your css code here
</style>
</head>
<body>
${body}
</body>
</html>
then in your java code:
String pageBody; // get page body by httpUrlConnection or okhttp or...
String html = FileUtils.readFromAssets("page.html", context);
// replace pageBody with ${body} in your html file
html = html.replace("${body}", pageBody);
WebView webView = (WebView) getView().findViewById(R.id.webView);
webView.getSettings().setAllowFileAccess(true);
WebSettings settings = webView.getSettings();
settings.setDefaultTextEncodingName("utf-8");
settings.setJavaScriptEnabled(true);
webView.loadDataWithBaseURL("file:///android_asset/", html, "text/html", "utf-8", null);

Unknown character in html inside webview android studio

I view a lot of htmls with text inside, but there seems to be one html that is not displayed correctly, for some reason all the tilde characters display an unknown character, this is strictly related to that particular html document?
Since all the others htmls are viewed perfectly in webview, i guess it has nothing to do inside android studio?
Intial portion of html document
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<link href="Content/watermark.css" rel="stylesheet" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Código de Proceso Penal</title></head>
<script src="Scripts/jquery-2.1.4.min.js"></script>
CADE
This happens due to fact that Webview is not able to detect encoding.
If you are using Webview loadData() or void loadDataWithBaseURL() method, try passing "UTF-8" as encoding, you can check same here, on developer.android.com..
it this doesn't work try with "iso-8859-1" or "iso-8859-15" encoding

phonegap: loading remote html

I'm searching for a way to load remote html's in phonegap android app.
I'm using super.loadUrl("file:///android_asset/www/hello.html"); but how to load remote html page?
it's very simple Venkat,
just load required html page with the http request,
super.loadUrl("http://www.test.com/test1.html");
or you can load local html file like you did
super.loadUrl("file:///android_asset/www/hello.html");
and in hello.html used window.location in onLoad() javascript function to load external html page.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<!-- Change this if you want to allow scaling -->
<meta name="viewport" content="width=default-width; user-scalable=no" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>LoadUrl
<script type="text/javascript" charset="utf-8">
function onBodyLoad()
{
document.addEventListener("deviceready",onDeviceReady,false);
}
/* When this function is called, PhoneGap has been initialized and is ready to roll */
function onDeviceReady()
{
// do your thing!
window.location="http://170.60.26.20:8099/Sencha/Html/index.html";
}
</script>
</head>
<body onload="onBodyLoad()">
</body>
</html>
Please make sure you set the internet permission in android manifest file.

Displaying Android asset files in a WebView?

I have seen various discussions on the problem of serving WebView pages from assets, none of which seemed definitive.
I want to be able to use a webview to display html (and included css) files stored in the project assets.
I have found that wv.loadUrl("file:///android_asset/html_no_copy/demo_welcome.html") displays that file okay, but links in demo_welcome.html, either local (no url prefixing the file name) or absolute - the same form as fed to loadUrl - don't work. They get a "Web page not available" error displayed on the view.
WebView wv = (WebView)this.findViewById(R.id.splashWebView);
wv.loadUrl("file:///android_asset/html_no_copy/test.html"); // Works
or
wv.loadUrl("file:///android_asset/html_no_copy/demo_welcome.html"); // Works
But neither of the following links in demo_welcome.html work:
CLICK HERE<p>
OR HERE
I know I can get around this by writing a content provider, but that seems extreme.
I want this to work from SDK 1.6 (4) on up.
Does anyone know if this can be done with just HTML, or does one need to kluge up some code to load the data?
Well, I found something that seems to work (on 1.6 and 2.2), in spite of a warning that it would recurse.
I also discovered that a css style-sheet link inside the first and second page both work without the following intercept. Odd and it makes me a bit nervous. Thoughts?
Here's the code:
WebView wv = (WebView)this.findViewById(R.id.splashWebView);
wv.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
});
wv.loadUrl("file:///android_asset/html_no_copy/demo_welcome.html");
Here's the file contents:
demo_welcome.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Demo Html</title>
<link rel="stylesheet" type="text/css" href="demo.css" />
</head>
<body>
<H1>Testing One Two Three</H1>
CLICK HERE<p>
OR HERE
</body>
</html>
test.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="test.css" />
<title>Insert title here</title>
</head>
<body>
<H1>TEST.HTML</H1>
</body>
</html>
instead of loadUrl, try using the loadDataWithBaseURL method:
wv.loadDataWithBaseURL("fake://not/needed", html, mimeType, encoding, "");

Categories

Resources