How to draw Hindi text on Webview in android? - android

I am new in android so please help me. my question is
I want to draw hindi text on WebView in android, I am using following code
<string name="hindi_content">विज्ञान के इस युग में मानव को जहां कुछ वरदान मिले है </string>
WebView wv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String s = getResources().getString(R.string.hindi_content);
wv = (WebView)findViewById(R.id.webView);
wv.loadData(s, "text/html", null);
}
but it displaying the special characters. so please help me.

Use the following to load हिन्दी:
wv.loadData(s, "text/html; charset=utf-8", "utf-8");

This happens because of a bug with the encoding parameter of loadData in most Android versions. This parameter is ignored for some reason so the UTF-8 based hindi characters will not be rendered. To fix this you can use one of the following alternatives.
webview1.loadData(hindi_content, "text/html; charset=UTF-8", null);
webview1.loadDataWithBaseURL(null, hindi_content, "text/html", "utf-8", null);

Related

Android: How to convert local string(html) to html page and display in the Webview

The string contains the html page code. As the requirement, it better not to store in the file. How to represent it in the Webview?
Hi if you string contains the html page code then you can directly load in Webview like below.
webView.loadData(webData, "text/html; charset=UTF-8", null);
Try this:
WebView wv = (WebView)this.findViewById(R.id.myWebView);
wv.getSettings().setJavaScriptEnabled(true);
wv.loadDataWithBaseURL(null, /*Your HTML string*/, "text/html", "utf-8", null);
Check out this: http://developer.android.com/reference/android/webkit/WebView.html
String summary = "<html><body>Your <b>HTML</b> code.</body></html>";
webview.loadData(summary, "text/html", null);
for more reference check this answer..
https://stackoverflow.com/a/14002475/5362535

How to avoid unnecessary characters in WebView

I am setting String in WebView in Android, but i am getting such characters http://img4.imageshack.us/img4/5200/hkgm.jpg. How to avoid them ? IF i put a log and see then it will be proper but only in WebView it is not working properly
Thanks in advance
Code :
String text = "<html><body style=\"text-align:justify\"> %s </body></Html>";
String summary = rssStr.get(position).getEncodedContent();
Log.d("String", summary);
web.loadData(String.format(text, summary), "text/html", "utf-8");
By setting the Encoding type in the Webview can resolve this issue,
wv.loadDataWithBaseURL(null, data, "text/html", "UTF-8", null);

Why iframe works in webview on Android 4.0+ ICS?

I load a Google Docs' iframe into a webview in Android, this iframe is loading a PPT file (Power Point file) from a external server of Google Docs. This is the Android Code:
public class Test_iframeActivity extends Activity {
private WebView webView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webView = (WebView) findViewById(R.id.wv);
webView.getSettings().setJavaScriptEnabled(true);
//String customHtml = "<html><body><h1>Hello, WebView</h1></body></html>";
String customHtml = "<iframe src='http://docs.google.com/viewer?url=http://www.iasted.org/conferences/formatting/presentations-tips.ppt&embedded=true' width='100%' height='100%' style='border: none;'></iframe>";
webView.loadData(customHtml, "text/html", "UTF-8");
}}
My question is... why I can see the iframe works fine into Android 4.0 but I can't see it into Android 2.1 to 2.3? (I don't know if in Android 3 works).
SOLVED!
The mistake was the ASCII encoding... I shoud replace the #, %, /, and ? by other characters, please check http://developer.android.com/reference/android/webkit/WebView.html#loadData(java.lang.String, java.lang.String, java.lang.String) for more information.

Why Android WebView does not display properly HTML page with Hebrew text when text-align set to "justify"

I want to display local html file on a WebView. (Android 2.3.3)
The HTML contains Hebrew text. I want the text to be justified, so in my css file I do the following:
body
{
text-align: justify; direction: rtl;
}
But for some reason the text end up being messed up:
And this is definitely not "justified" but more aligned to the left.
Any idea how can overcome this problem?
It's working perfectly fine on any other browser than the WebView. (Including WebKit based ones)
This code worked for me:
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings settings = myWebView.getSettings();
settings.setDefaultTextEncodingName("utf-8");
String webtext = "שלום";
String summary = "<html lang=\"he\"><body><p dir=\"rtl\">" + webtext + "</p></body></html>";
myWebView.loadData(summary, "text/html", null);
}

Display html formated table using webview in Android

I am trying a lot but it is not wroking. Here's my code:
public class SchofferStr extends Activity {
String summary = "<html><body>You scored <b>192</b> points.</body></html>";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
WebView webview = new WebView(this);
setContentView(webview);
webview.loadData(summary, "text/html", "utf-8");
}
}
the summary string i have is a lengthy htmlformatted table. But problem is this code is not even working for this simple html formated string. What is it that im doing wrong?
Please help, im stuck.
Try:
webview.loadDataWithBaseURL(null, summary, "text/html", "UTF-8", null);

Categories

Resources