How Can I Check If My Device Is Capable To Render Emoji Images Correctly?
Solution 1:
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.
PaintmPaint=newPaint();
privatebooleanemojiRenderable(String emoji) {
floatwidth= mPaint.measureText(emoji);
if (width > 7) returntrue;
returnfalse;
}
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.
Solution 2:
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)
Solution 3:
Inspired from the two methods found in the above file.
publicstaticbooleancanShowEmoji(String emoji) {
Paintpaint=newPaint();
floattofuWidth= paint.measureText("\uFFFE");
floatstandardWidth= paint.measureText("\uD83D\uDC27");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
return paint.hasGlyph(emoji);
} else {
floatemojiWidth= 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.
}
}
Post a Comment for "How Can I Check If My Device Is Capable To Render Emoji Images Correctly?"