I'm facing a problem with BrowserField in Blackberry, i have some HTML content that contains some characters like " ' " but when i'm trying to show this content in my BrowserField i can't display those chars it appears like this " ? "
I changed BrowserField by RichTextField and i can see my characters there so i think the problem is from the BrowserField, i tried to change the encoding like this :
HttpHeaders headers = new HttpHeaders();
headers.addProperty(HttpHeaders.HEADER_CONTENT_TYPE,HttpHeaders.CONTENT_TYPE_TEXT_HTML);
headers.addProperty(HttpHeaders.HEADER_ACCEPT_CHARSET, "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
config.setProperty(BrowserFieldConfig.NAVIGATION_MODE, BrowserFieldConfig.NAVIGATION_MODE_POINTER);
config.setProperty(BrowserFieldConfig.ALLOW_CS_XHR, Boolean.TRUE);
config.setProperty(BrowserFieldConfig.HTTP_HEADERS, headers);
But the problem is still there :(
can you please help me
Best Regards
The problem is likely due to the difference between ISO-8859-1 and its superset Cp1252 (=Windows-1252). One of the extra charactes are non-ASCII quotes as MS Word produces.
Pages sent to the browser may say they are in ISO-8859-1 (Latin-1) but in reality be in the superset Windows-1252 (Windows Latin-1). Even on a Mac it went okay in all browsers. In this case you have to change on the server side to encoding Cp1252.
response.setEncoding("Cp1252");
or
response.setContentType("text/html; charset=Windows-1252");
Of course UTF-8 does not have this problem and is international. So a viable alternative.
Related
my app work with SMSC, and i need to get involve in sms before it send,
i try to send from the mobile that string
"hello this is test"
And when I check the smsc I got this as binary string of my text:
userData = "c8329bfd06d1d1e939283d07d1cb733a"
the encoding of this string is:
<Encoding:ASCII-8BIT>
I know that probably this userData is in GSM encoding in binary-string
so how can i get from userData back the clear text string ?
this question is for english lang, because in Hebrew I can get back the
string with this code:
[userData].pack('H*').force_encoding('utf-16be').encode('utf-8')
but in english i got error:
Encoding::InvalidByteSequenceError: "\xDA\xF3" followed by "u" on UTF-16BE
What I was try is to detect the binary string with ICU, and I got:
"ISO-8859-1" and the language that detected is: 'PT', that very strange cause my languages is English or Hebrew.
anyway i got lost with encoding stuff, so i try to encode to each name of list from Encoding.list
but without luck until now
thanks in advance
Shmulik
OK,
For who that also have this issue, i got the solution, thanks to someone from #ruby irc community (i missed his nickname)
The solution is:
for ascii chars that interpolate to binary:
You need that:
"c8329bfd06d1d1e939283d07d1cb733a".scan(/../).reverse_each.map { |h| h.to_i(16) }.pack('C*').unpack('B*')[0][2..-1].scan(/.{7}/).map.with_object("") { |x, s| s << x.to_i(2) }.reverse
Remember I sent this words in sms:
"hello this is test"
And that it has become in binary to:
"c8329bfd06d1d1e939283d07d1cb733a"
The reason that i got garbage in any encoding is, because the ascii chars is 7bits GSM, so only first 7bits represents the data but each another encoding uses at least 8bits, so that what the code actually do.
But this is just for ascii char set.
In another language like I use Hebrew, the SMS send as ucs2
So this code work for me:
[your_binary_string].pack('H*').force_encoding('utf-16be').encode('utf-8')
Very important to put the binary string in array
So that all for now.
If anybody want to translate and explain what exactly happen in the code for ascii char set, be my guest and welcome.
Shmulik
I'm writing a multilanguage WebBroker application (for Apache 2.2) which display unicode encoded data from an oracle database. The same data with the same data-aware components (Devart's ODAC) in a test program written in Delphi XE7, are displaying correctly.
My problem occured in the WebBroker where I'm facing with a strange behavior when I'm using a PageProducer to prepare the content for the response
When I'm using the follow code in the action :
Response.ContentType := 'text/html; charset=UTF-8';
PageProducer1.HTMLFile:= htmltemplate
Response.Content :=
PageProducer1.Content+
'Label 1 ='+Label1fromDB+
' Label 2='+Label2fromDB+
'</body></html>';
Response.SendResponse;
the result in the webbrowser is that all the non-latin chars that was not inserted by the PageProducer but already existed in the htmltemplate file (which has declared as utf-8 with ) replaced by other not correct chars, the text that was inserted by the PageProducer and was retrived from the database also not displayed correctly but the extra labels, Label1fromDB and Label2fromDB which are added to the content response as showing in the code above are displayed correctly having also the same chars which are inside the htmltemplate.
Now, when I omit the declaration
Response.ContentType := 'text/html; charset=UTF-8'
the content of the htmltemplate are diplaying correctly but all the other texts , the text filled by PageProducer and the two labels Label1fromDB and Label2fromDB not correctly
Can you please help me identify where the problem is and what have I do in order to be able to serve unicode multilanguage content via web broker?
You are having issues with different Unicode encodings.
Both PageProducer.Content and Response.Content are UTF16 encoded strings. Your htmltemplate is encoded in UTF8 and is not correctly interpreted by PageProducer.
Most likely cause is that htmltemplate file does not have UTF8 BOM at beginning and PageProducer will interpret that file encoding as default ANSI. If that is so, adding UTF8 BOM should solve your problem.
I got a serious problem regarding Unicode and utf8,
I saved a paragraph of Arabic/Persian text file into notepad and saved it, now I saw my information like
Êæ Çíä ÓæÑÓ ÈÑäÇãå ÚÏÏ ÏáÎæÇåí Ñæ ÇÒ æÑæÏí ãííÑå æ Èå Øæá åãæä ÚÏÏ ãËáËí Ñæ ÑÓã ãí ˜äå
my question is how to get back my data, it is important for me to get this data back, thanks in advance
The paragraph was scrambled by saving as code page 1256 (Arabic/Persian), then interpreted as code page 1252 (Western Europe), and finally saved as Unicode text. You can use C# to reverse this procedure:
string scrambled = "Êæ Çíä ÓæÑÓ ÈÑäÇãå ÚÏÏ ÏáÎæÇåí Ñæ ÇÒ æÑæÏí ãííÑå æ " +
"Èå Øæá åãæä ÚÏÏ ãËáËí Ñæ ÑÓã ãí ˜äå";
byte[] bytes = Encoding.GetEncoding("windows-1252").GetBytes(scrambled);
string plainText = Encoding.GetEncoding("windows-1256").GetString(bytes);
Console.WriteLine(text);
The plain text output is:
"تو اين سورس برنامه عدد دلخواهي رو از ورودي ميگيره و به طول همون عدد مثلثي رو رسم مي کنه"
On Linux you can use Gedit to open it as a 1256 encoded file:
gedit shahnameh.txt --encoding WINDOWS-1256
You can do the same work via gui. You just need select the correct encoding from "open" dialog box when opening a file. It should be at the bottom of the open dialog.
I have been searching for an answer all around the web, but couldn't find anything.
I am developing Blackberry Webworks application and the problem is with dialog and unicode. For example:
when I use simple javascript alert(unicodeMsg); unicode works fine, I can use any character including Russian or Lithuanian. The problem is that the alert box has title "JavaScript Alert" and it annoys a bit.
when I use native alert either phonegap or webworks like:
blackberry.ui.dialog.standardAskAsync(unicodeMsg,
blackberry.ui.dialog.D_OK, {
title : unicodeTitle,
size: blackberry.ui.dialog.SIZE_MEDIUM,
position : blackberry.ui.dialog.CENTER
});
it doesn't show any unicode characters. I tried pretty much everything (setting my document in utf-8, using \uxxxx characters, changing meta tags from utf-8 to windows-1257 but nothing works)
I suppose the problem is not with html or js documents neither with the script. Can someone help me?
You need to encode the unicode characters like so text: unescape(encodeURIComponent(unicodeStr)) .
There is an example here - http://blackberry-webworks.github.com/WebWorks-API-Docs/WebWorks-API-Docs-next-BB10/view/blackberry.invoke.html
i have a problem to run flash file on android 4.0, I used intent but nothing happened and now i am using web view to run but only sound is coming and only white screen is on display.
please help me to solve my problem, i am stuck here and i am in big trouble. below is my code that i used.
webView = (WebView)findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setAllowFileAccess(true);
//webView.getSettings().setPluginsEnabled(true);
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
String html = "<object width=\"550\" height=\"400\"> <param name=\"movie\" value=\"file:///sdcard/mainV7.swf\"> <embed src=\"file:///sdcard/mainV7.swf\" width=\"550\" height=\"400\"> </embed> </object>";
String mimeType = "text/html";
String encoding = "utf-8";
webView.loadDataWithBaseURL("null", html, mimeType, encoding, "");
Please check this link : Flash Support for Android
Also check whether your device supports flash file or not.