Android Question textwriter supported encodings - Solved

Discussion in 'Android Questions' started by padvou, May 22, 2015.

  1. padvou

    padvou Active Member Licensed User

    Hello,
    what are the supported encodings for textwriter?

    Dim TR as textwriter
    tr.initialize2(someoutputstream, encoding as string)
     
  2. klaus

    klaus Expert Licensed User

    Extract from chapter 14.10.6 Text encoding in the Beginner's Guide:

    Android can use following character sets:
    - UTF-8 default character-set
    - UTF -16
    - UTF - 16 BE
    - UTF - LE
    - US-ASCII ASCII character set
    - ISO-8859-1 almost equivalent to the ANSI character-set
    - Windows-1251 cyrillic characters
    - Windows-1252 latin alphabet

    Example:
    tr.initialize2(someoutputstream, "Windows-1252")
     
    DonManfred and padvou like this.
  3. padvou

    padvou Active Member Licensed User

    Hi Klaus, thank you for responding.
    Are these all?
    Because I tried "ISO-8859-7" and it seemed to work, that's why I'm asking for this
     
  4. padvou

    padvou Active Member Licensed User

    Could this be the answer to my question?
    If yes, then why do I get this exception?
    Code:
    java.nio.charset.UnsupportedCharsetException: x-IBM737


        at java.nio.charset.Charset.forName(Charset.java:
    303)
        at anywheresoftware.b4a.objects.streams.File$TextWriterWrapper.Initialize2(
    File.java:482)
        at bt.spp.printing.main._printer_connected(main.java:
    504)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:
    511)
        at anywheresoftware.b4a.BA.raiseEvent2(BA.java:
    187)
        at anywheresoftware.b4a.BA$
    3.run(BA.java:332)
        at android.os.Handler.handleCallback(Handler.java:
    725)
        at android.os.Handler.dispatchMessage(Handler.java:
    92)
        at android.os.Looper.loop(Looper.java:
    176)
        at android.app.ActivityThread.main(ActivityThread.java:
    5365)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:
    511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:
    1102)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:
    869)


        at dalvik.system.NativeStart.main(Native Method)
    java.nio.charset.UnsupportedCharsetException: x-IBM737
     
    Last edited: May 22, 2015
    DonManfred likes this.
  5. klaus

    klaus Expert Licensed User

    Probably not.

    The ones I posted are the ones I knew of.
    In the Android documentaion the list is even smaller, but it specifies the garantied Charsets.
    I Googled a bit and found this site List of Supported Character Encodings in Java.
    Then I looked at the Android documentaion and wrote this code to get the avalable Charsets:
    Code:
    Sub GetAvalableCharsets
        
    Dim jo As JavaObject
        
    Dim CharSets As Map
      
        jo.InitializeStatic(
    "java.nio.charset.Charset")
        
    Dim jo1 As JavaObject
        jo1.InitializeStatic(
    "java.util.SortedMap")
      
        jo1 = jo.RunMethod(
    "availableCharsets"Null)
        
    Dim size As Int
        size = jo1.RunMethod(
    "size"Null)
        
    Dim jo2 As JavaObject
        jo2.InitializeStatic(
    "java.util.Set")
        jo2 = jo1.RunMethod(
    "keySet"Null)

        
    Dim obj(size) As Object
        obj = jo2.RunMethod(
    "toArray"Null)
        
    For i = 0 To size - 1
            
    Log(obj(i))
        
    Next
    End Sub
    On my Sony xperia z1 the list looks like this:
     
    Last edited: May 22, 2015
    wendays and padvou like this.
  6. padvou

    padvou Active Member Licensed User

    Great code!
    So, what If I wanted to add a charset?
    What does it depend on? The device? Java version?
     
  7. klaus

    klaus Expert Licensed User

    Sorry, but this is beyond my knowledge.
     
    padvou likes this.
  8. DonManfred

    DonManfred Expert Licensed User

    beyond mine too but i guess it is the JAVA version
     
  9. padvou

    padvou Active Member Licensed User

    I started using this:
    Code:
    printer.Initialize2(cmp20.OutputStream,"x-JavaUnicode")
    It prints everything I want to print, provided I send extended characters like this:
    Code:
    Case  t.CharAt(i)="Π"
    Text2Return=Text2Return& 
    Chr(143)
    However, I cannot locate the € (Euro) sign...
     
  10. klaus

    klaus Expert Licensed User

    What Charset does the printer expect ?
    Have you tried windows-1251 ? There the € character is Chr(136).
     
  11. padvou

    padvou Active Member Licensed User

    Solved changing encoding just when the euro sign is needed and then back to Greek for the rest characters.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice