alexzhirkevich / custom-qr-generator

Android library for creating QR codes with logo, custom shapes, colors, background image. Powered by ZXing
MIT License
173 stars 18 forks source link

Charset in Vcard #24

Closed huyngo1801 closed 1 year ago

huyngo1801 commented 1 year ago

I've generated an Vcard QRcode:

val drawableBitmap = QrCodeDrawable( qrCodeVCard, qrOptions, Charsets.UTF_8 ) but its not show correct Name in Vcard

image

alexzhirkevich commented 1 year ago

Try another encoding, for ex. utf-16

huyngo1801 commented 1 year ago

thank you for helping

huyngo1801 commented 1 year ago

I want to create new VCard(4.0) and the charset is not working.

fun interface NewQrData : QrData {

data class VCard(
    val id: String? = null,
    val full_name: String? = null,
    val phoneNumber: String? = null,
    val email: String? = null,
    val gender: String? = null,
    val lastUpdated: Long? = null,
    val timeZone: String? = null,
    val company: String? = null,
    val note: String? = null,
) : QrData {

    override fun encode(): String = buildString {
        append("BEGIN:VCARD\n")
        append("VERSION:4.0\n")
        if (full_name != null) {
            append("FN:${full_name}\n")
            append("KIND:individual\n")
            append("N:${full_name}\n")
        }

        if (id != null) {
            append("UID:$id\n")
        }

        if (phoneNumber != null)
            append("TEL:${phoneNumber}\n")

        if (email != null)
            append("EMAIL:${email}\n")

        if (gender != null) {
            if (gender == Contains.MALE)
                append("GENDER:M\n")
            else
                append("GENDER:FM\n")
        }

        if (timeZone != null) {
            append("TZ:$timeZone\n")
        }

        if (company != null)
            append("ORG:$company\n")

        if (note != null) {
            append("NOTE:$note\n")
        }

        append("END:VCARD")
    }
}

}

alexzhirkevich commented 1 year ago

Charset is passed as a hint for zxing lib. Tbh i can’t do anything here. What name are u trying to encode?

huyngo1801 commented 1 year ago

I used your QRData.VCard charset still ok, but when I use NewQrData its not working

val qrCodeVCard = generateVCardUserQRCode(user)

val drawableBitmap = QrCodeDrawable( qrCodeVCard, qrLogoGolf, Charsets.UTF_8 )

private fun generateVCardUserQRCode(user: User): QrData { val timeZone = TimeZone.getDefault().id return NewQrData.VCard( id = user.id, full_name = user.full_name, phoneNumber = user.phone_number, email = user.email, gender = user.gender, lastUpdated = user.last_updated, timeZone = timeZone, note = generateNoteUserQRCode(user) ) }

alexzhirkevich commented 1 year ago

It's weird, cause zxing encoder takes only result of .encode() (no difference which QrData you pass, internal or custom). And charset is not linked to any of QrData:

https://github.com/alexzhirkevich/custom-qr-generator/blob/e6a7a6dd65939c263122f6dabecf4bbeb575e6f7/custom_qr_generator/src/main/java/com/github/alexzhirkevich/customqrgenerator/vector/QrCodeDrawable.kt#L74-L83

Mb ios phonebook is not ready for vcard v4 :). Did you try UTF-16?

alexzhirkevich commented 1 year ago

Hm, your implementation of vcard is really broken on ios. Try this website. It decodes your vcard normally. I think the reason is exactly ios phonebook

huyngo1801 commented 1 year ago

oh, its work in that website (utf 8), Why i used your base Vcard its show normally but mine

huyngo1801 commented 1 year ago

OH, I founded the problem, its about VERSION:4.0, 3.0 is work, ios phonebook can't read correctly with 4.0 Vcard

huyngo1801 commented 1 year ago

Thank you for helping me <3