how can I check if my device is capable to render Emoji images correctly?
Asked Answered
N

3

3

I'm using Emoji unicode in a View. On most devices the images appear ok, but on one of my low-end device(android 2.3) they are rendered as little squares.

Can I check whether the device support emoji? So that I can publish my apk while won't show that ugly squares on some devices.

enter image description here

Nystrom answered 12/8, 2014 at 9:53 Comment(9)
Use a dedicated FREE font with all the glyphs.Brigittebriley
I'm facing two problems: First, we haven't found a FREE emoji reource yet(but we're trying). Second, we still want to do this check(if possible) for some other reasons. ThanksNystrom
I can't see know how can you determine if a glyph is shown correctly or as a square? for Android it's the very same! there's no error code in return. So, really, use a FREE font which supports emojis (there are a TON). You can even consider to take the font out of another (working) device and use that one.Brigittebriley
I will try. Anyway, I have to find a solution/workaroundNystrom
you're right, but we will use emoji for business reasons, we must make sure that's allowed by its license. See https://mcmap.net/q/566716/-emoji-copyright-closed/…Nystrom
Well, you said you have some devices (presumably 4.x) where the app runs fine. Take out the system font from that device and use it as a custom font for your app... (you'll need to root the "donor" device). If it is a system font, in Android, everything is open source / free. That's Google's power!Brigittebriley
Thanks your advice. I will have try.Nystrom
As a last resource, you might use some SVG graphics (which is vectorial, as TTF fonts) - You will need a free 3rd party library. But then you'll have to save it as PNGs (if not existing) into your SD card and insert it in text as <img src='...' /> and use HTML.fomHTML. Quite an overkill.Brigittebriley
I know this is an old thread but just in case. Just because you have a license to use a font on a device, it doesn't mean you are allowed to redistribute the font with your app. @Nystrom is right in wanting to check the font permissions before redistributing.Abidjan
I
6

This is a late answer but I recently ran into a similar problem. I needed to filter through a List<String> and filter out emojis that couldn't be rendered on the device (i.e., if the device was old and didn't support rendering them).

What I ended up doing was using Paint to measure the text width.

Paint mPaint = new Paint();
private boolean emojiRenderable(String emoji) {
    float width = mPaint.measureText(emoji);
    if (width > 7) return true;
    return false;
}

The width > 7 part is particularly hacky, I would expect the value to be 0.0 for non-renderable emoji, but across a few devices, I found that the value actually ranged around 3.0 to 6.0 for non-renderable, and 12.0 to 15.0 for renderable. Your results may vary so you might want to test that. I believe the font size also has an effect on the output of measureText() so keep that in mind.

Overall I am not sure if this is a great solution but it's the best that I've come up with so far.

Isopod answered 14/10, 2015 at 18:23 Comment(1)
this is a great solution, because no other two methods suit: both flag/penguin and getPixels comparison fail for SDK10Kyser
P
1

please check the source code from Googles Mozc project. The EmojiRenderableChecker class seems to work pretty well! https://github.com/google/mozc/blob/master/src/android/src/com/google/android/inputmethod/japanese/emoji/EmojiRenderableChecker.java

it's like a compat version for Paint.hasGlypgh (added in Marshmallow). https://developer.android.com/reference/android/graphics/Paint.html#hasGlyph(java.lang.String)

Pavement answered 12/12, 2016 at 12:11 Comment(0)
H
0

https://android.googlesource.com/platform/packages/inputmethods/LatinIME/+/master/java/src/com/android/inputmethod/keyboard/emoji/EmojiCategory.java#441

Inspired from the two methods found in the above file.

   public static boolean canShowEmoji(String emoji) {
    Paint paint = new Paint();
    float tofuWidth = paint.measureText("\uFFFE");
    float standardWidth = paint.measureText("\uD83D\uDC27");

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return paint.hasGlyph(emoji);
    } else {
        float emojiWidth = paint.measureText(emoji);
        return emojiWidth > tofuWidth && emojiWidth < standardWidth * 1.25;
        // This assumes that a valid glyph for the cheese wedge must be greater than the width
        // of the noncharacter.
    }
}
Hymeneal answered 8/10, 2020 at 7:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.