BrowserComponent will not display chinese on iOS

14 views
Skip to first unread message

Gareth Murfin

unread,
Jan 21, 2019, 7:57:05 AM1/21/19
to CodenameOne Discussions
I have found many conversations on stackoverflow but none of them worked. I am trying to display chinese in a BrowserComponent on iOS, I build the html as a string then save it to FileSystemStorage, then view it using setUrl, but the result is always garbage when I view it on a BrowserComponent on iOS. 

If I make a form and add a button with this in it displays well but I need to be able to view it in a BrowserComponent since it has links etc. Is there any way to display chinese on a BrowserComponent?

Tried 
out.write(html.getBytes("UTF-8"));
 Util.writeUTF(html, new DataOutputStream(out));

and many more solutions, but not been able to  get it to work, it works on Android without any special code. Any ideas?

Gareth Murfin

unread,
Jan 21, 2019, 8:44:39 AM1/21/19
to CodenameOne Discussions
Note that after saving it etc, i can re-load it and display and nothing is lost, so I think there is something weird about the browsercomponent on ios. 

Ie instead of:

browser.setURL(newHTMLpath); //wont display chinese properly

I can do 

browser.getParent().removeAll();/////            
              f.setLayout(new FlowLayout());
            ///READ I NWHAT WE SAVED SEE IF ITS STILL IN TACT?
            InputStream myinput = FileSystemStorage.getInstance().openInputStream(newHTMLpath);      
            String arse = Util.readToString(myinput);
         
           StringTokenizer st = new StringTokenizer(arse," ");
            while (st.hasMoreElements())
            {
                String s =(String) st.nextElement();
                 f.add(new SpanLabel(s));////does display chinese properly

Shai Almog

unread,
Jan 21, 2019, 10:32:05 PM1/21/19
to CodenameOne Discussions
A better way is to use a writer:

Writer w = new InputStreamWriter(input, "UTF-8");
w
.write(string);

Check the string in the debugger first to make sure it wasn't corrupted before this stage.

Gareth Murfin

unread,
Jan 23, 2019, 3:16:59 AM1/23/19
to CodenameOne Discussions
Wow, a new way I have not seen, thanks Shai! Fingers crossed, will give it a go!

Gareth Murfin

unread,
Jan 23, 2019, 7:33:52 AM1/23/19
to CodenameOne Discussions
Yeah still no luck, its very weird, still displays fine on span labels, but in browsercomponent its all messed up. Kind of stops the development of this chinese/japanese learning app...on iphone at least.... alternatives? I was thinking of making the screens using labels and buttons, a lot more work than just using the html and might be slow but it would work I think. 

Thanks for all the help, if you have any further ideas let me know, it would be great if you could test it on your iphone sometime, or I can prepare a simple test program to demo the issue.

Gareth Murfin

unread,
Jan 23, 2019, 7:35:09 AM1/23/19
to CodenameOne Discussions
ps I assume you meant Writer w = new OutputStreamWriter(out, "UTF-8");

Gareth Murfin

unread,
Jan 23, 2019, 7:43:47 AM1/23/19
to CodenameOne Discussions
Oh my god... I just release a missing speech mark in the meta tag, it DOES work.. Im so dumb.. thanks for everything, made my day!!!! Sorry for all the red herrings.
Reply all
Reply to author
Forward
0 new messages