murdock
murdock

Reputation: 49

Android question mark in TextView?

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.

Upvotes: 2

Views: 4292

Answers (3)

Pradip
Pradip

Reputation: 57

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)

Upvotes: 0

Shambhavi
Shambhavi

Reputation: 51

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

Upvotes: 0

MJ93
MJ93

Reputation: 5286

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

newLyrics = new String(oldString.getBytes("UTF-8"),"UTF-8");

Upvotes: 2

Related Questions