2

I have a problem with accented characters in a TextView in an Android activity. The rendering shows me question marks instead chars "è" and "à". The flow is: Get a midi file from web resource --> extract lyrics --> put lyrics in a TextView. I don't understand if is a problem with encoding or charset. I try to encode a file with "UTF-8" or "ISO..." but every attempt failed. Can you help me?

Thanks in advance.

Nik Reiman
  • 39,067
  • 29
  • 104
  • 160
murdock
  • 49
  • 1
  • 3
  • 1
    If they are showing up as `?`, that usually implies that a glyph is missing in the font. However, those characters should be supported. – CommonsWare May 22 '14 at 22:48
  • I confirm these charaters exist in the Android **standard font**, as they are present in Italian language. I suppose that the original file isn't **UTF-8 encoded** OR you are using a custom font. – Phantômaxx May 23 '14 at 07:12
  • You have to know the encoding of the lyrics; it's unlikely to be UTF-8. – CL. May 23 '14 at 07:28
  • @CommonsWare I'm trying to change a font – murdock May 23 '14 at 09:50
  • @CL The problem is that the file is a midi and I don't understand how to extract encoding informations for lyrics sequence. – murdock May 23 '14 at 10:01
  • MIDI files do not have encoding information. – CL. May 23 '14 at 10:08
  • OK. Therefore it's impossible know lyrics encoding. That's true? – murdock May 23 '14 at 10:14
  • @CommonsWare, Der Golem, I have tried to change font but the activity show question marks again. I think that the problem occur when I get a file from web. I have tried to log lyrics String before put its in a TextView and print question marks too. – murdock May 23 '14 at 11:27

3 Answers3

2

You can try something like this before you put the lyrics into a textview:

newLyrics = new String(oldString.getBytes("UTF-8"),"UTF-8");
MJ93
  • 4,966
  • 8
  • 32
  • 50
  • Hi @MJ93, your solution is probably correct but not for me. My problem is on the encoding midi file that I get from web resource. I need to encode correctly the file before extract lyrics text with MIDI Api. – murdock May 23 '14 at 13:56
0

Check this out once:

https://www.csie.ntu.edu.tw/~r92092/ref/midi/

Midi files basically comprises of binary format + ascii values as header data, so if you can convert that and represent it like-
If you can encode that binary format to base64, this will turn any data into ascii safe text

Shambhavi
  • 51
  • 5
0

You can try below code:

//String encode function
fun encodeEmoji(message: String): String {
    try {
        return URLEncoder.encode(
            message,
            "UTF-8"
        )
    } catch (e: UnsupportedEncodingException) {
        return message
    }

}


//String decode function
fun decodeEmoji(message: String): String {
    val myString: String? = null
    try {
        return URLDecoder.decode(
            message, "UTF-8"
        )
    } catch (e: UnsupportedEncodingException) {
            return message
    }

}

use of function

    var string:String=CommonMethod.encodeEmoji("your string")

    string=CommonMethod.decodeEmoji(string)
Pradip
  • 57
  • 1
  • 3