Webview cant read </br> from predefined html file - android

I have a html file that contain a lot of text and basic html tags. The file is inside res/raw folder.
However, when i tried to show this html from my webview, </br> is not working, while <b></b> is fine.My min SDK is 8 and target SDK is 15.
This is the screen shoot :
This is the html file :
<!DOCTYPE HTML>
<article align="center">
Printf(“Hello World ^_^”);</br></br>
<b>This section will explain about the objective of this apps.</b></br>
This apps is designed for those who want to learn Computer Science (programming), with no experience necessary (so you don’t have to worry about your age, background, education, etc. EVERYONE can learn programming!).</br>
This apps will teach you about the basics of the programming using C languange.</br>
</article>
This is webview code :
webChapter.loadUrl("file:///android_res/raw/hello_world.html");
I tried this one, but no luck, the file even cant be read :
webChapter.loadDataWithBaseURL("file:///android_res/raw/", "hello_world.html", "text/html", "UT-8", "");
Thanks :D

Use <br> instead of </br>
http://www.w3.org/TR/html5/text-level-semantics.html#the-br-element

Related

ionic 2 image doesn't show up in android phone

I have a problem in ionic2 , my image doesn't show up in my android phone
its run normally in localhost...
{{item.name}} = A+
And my image =/assets/image/A+.png
<ion-avatar item-left>
<img src="../assets/image/{{item.name}}.png">
</ion-avatar>
I have used Ionic 2 a lot for iOS but not Android. For my apps I would set the src to be:
<img src="assets/image/{{item.name}}.png">
Rather than
<img src="../assets/image/{{item.name}}.png">
Take a look at this forum post
Seems like a device is accessing assets through /android_assets/www/<your path relative to index.html>
You need to add [] to your src attribute otherwise your img tag is being read in the html at this exactly.
<img src="assets/image/{{item.name}}.png">
and obviously your file name is not {{item.name}}.png . It should be
<img [src]="assets/image/{{item.name}}.png">
to allow dynamic content.
I also think it is ../assets/image as your build folder sits on the same level as your assets folder
I put same image under these folders and it worked for me:
1) www/assets/img/
2) src/assests/img/
then in HTML code:
<img src="assets/img/image.png">

Android - Parse text of Html code und don't parse quotes at attributes

I want to parse following code to html code and show in a WebView. This works fine, but...
Code to parse:
<img src="http://...jpeg" alt="„Indoor Maps“ von Google" align="left" style="padding-right:5px">\n\n\nEinfachere Navigation in Gebäuden verspricht Indoor Maps von Google. Der Praxis-Test von COMPUTER BILD im Hamburger „Alsterhaus“ verlief aber kurios.<br>Foto: ComputerBILD<br>
attempt 1) Html.toHtml(Code) - The umlauts and quotes of the texts where parsed fine and the img-tag is still valid (quotes). But some img-attributes were removed, like alt and align. Result:
<p><img src="http://...jpeg"> Einfachere Navigation in Gebäuden verspricht Indoor Maps von Google. Der Praxis-Test von COMPUTER BILD im Hamburger „Alsterhaus“ verlief aber kurios.<br>\nFoto: ComputerBILD<br>\n</p>\n
attempt 2) external library: org.apache.commons.lang3.StringEscapeUtils.escapeHtml4(Code) - All umlauts and quotes where parsed. The img-tag is corrupted by parsing the quotes. Now i can't show the image on a WebView. The img-tags where not removed. Result:
<img src="http://...jpeg" alt="„Indoor Maps“ von Google" align="left" style="padding-right:5px">\n\n\nEinfachere Navigation in Gebäuden verspricht Indoor Maps von Google. Der Praxis-Test von COMPUTER BILD im Hamburger „Alsterhaus“ verlief aber kurios.<br>Foto: ComputerBILD<br>
I know there are a lot of posts of this category, but I can't find help to parse the html code and don't "touch" the quotes of attributes. I am stucking.
EDIT
This is the full Html code
StringBuilder html = new StringBuilder();
html.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">");
html.append("<html>");
html.append("<head>");
html.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">");
html.append("<title></title>");
html.append("</head>");
html.append("<body bgcolor=\"white\" leftmargin=\"0\" topmargin=\"0\">");
html.append(CODE AT THE TOP);
html.append("</body>");
html.append("</html>");
When I use UTF-8 I got the same result...
webView.loadData(html.toString(), "text/html", "iso-8859-1");
#Christiaan: This is the current result, when i set the unparsed code to WebView
Are you sure you want to use toHtml? It looks like you already have html and you should be using Html.fromHtml() or even nothing at all. Just keep the string as is and display it in the WebView?
Ah, now it looks like an encoding issue.
Try using UTF-8 in your source, your html and in this snippet that you want to insert.
As in:
html.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
and
webView.loadData(html.toString(), "text/html", "UTF-8");
Make sure the "CODE AT THE TOP" is also in UTF-8.
Make sure your source code is also in UTF-8 (search for Encoding in your ide)
I've found this post, now it works :) Android. WebView and loadData
myWebView.loadData(myHtmlString, "text/html; charset=UTF-8", null);
This works flawlessly, especially on Android 4.0, which apparently ignores character encoding inside HTML.
Tested on 2.3 and 4.0.3.

is it possible to put more than one html5 files in android app developed with dreamweaver cs5.5?

can we freely put more than one html5 file in android app developed with dreamweaver cs5.5?
example:
page1.html
page2.html
page3.html
then provide hyperlinks between the pages?
I tried doing this but the browser refuses to load the pages.
If you have your HTML files in the assets folder, say in a subfolder in /assets/html/, the following would work...
Java code could look something like this:
private void displayHTML5Page(String filename) {
webView.loadUrl("file:///android_asset/html/index.html");
setContentView(webView);
In HTML you access other pages using something like:
Here's a Second Page
Here's a Third Page
Here's a Fourth Page
....

named anchor not working webview android

In my little app i have a webview, i only have one html file in the assets folder. I'm trying to use a named anchor to make a Jump Link but it doesn't work. It only says Web page not available I don't know where i'm wrong. Is it trying to load a html file with the name tag i provided?
WebView mWebView = (WebView) findViewById(R.id.mywebview);
mWebView.loadUrl("file:///android_asset/topics.html");
EDIT:
here's my html
<html>
<body>
<a href=”#tip”>Go somewhere</a>
//a lot of <br/>...
Somewhere
<a name=”tip”></a>
</body>
</html>
And yes the topics.html is under assets/
Where does your program fail - with the loading or when you click the anchor? It sounds like the problem is with your HTML file, so you should probably show the code from that instead. :) Also, the full LogCat output is handy too. The more info the merrier.
I recently implemented a WebView, the HTML code is extremely straight-forward (since I know close to no HTML and just wanted an easy way to display documentation). A simple anchor is just this for example:
Navigating the application
...
<a name="q1"></a>
<p><b>Navigating the application</b></p>
<p>...sliding motion (to the left or to the right) with your finger...</p>
If your program is failing at the actual loading part, then ensure that you have placed the topics.html file correctly in the /assets/ folder in your project folder. It has to be at the very root of your project folder - ie. workspace\<projectname>\assets\topics.html
Your code for loading the webpage looks fine.

Android:How to refer css file within html in following situation

hi
In my application i need to display a html page in webview and that html page should refer to sdcard location for .css file (Using link href="...." tag).
I placed 2 files (i.e) html and css ) in sdcard->mibook.
I tried by giving absolute path as link href="/mnt/sdcard/mibook/0.css"
how can i specify path name android?
Edited:
Above problem solved : by using this- link href="file:///sdcard/mibook/0.css"
But i have following requirement,
i need to handle around 50+ html file every time ,
I placed all files as follows,
mibook->book1->pg90.sqlite
mibook->book1->links->o.css and 1.css
The sqlite file contains html pages. each html page has css reference as link href="/links/0.css"
These css file should be refer by html. how can i do this?
Try
link href="file:///sdcard/mibook/0.css"
Assuming Android >= 2.1

Categories

Resources