How can I check if my device is capable of displaying Emoji images correctly?
This is a late answer, but I faced a similar problem. I needed to filter through List<String>
and filter out emojis that could not be displayed on the device (i.e. if the device was old and did not support rendering them).
As a result, I used Paint
to measure the width of the text.
Paint mPaint = new Paint();
private boolean emojiRenderable(String emoji) {
float width = mPaint.measureText(emoji);
if (width > 7) return true;
return false;
}
The part is width > 7
especially hackish, I would have expected the value to be 0.0
for unimplemented emoji, but after a few devices I found that the value did indeed range from 3.0
to 6.0
for non-renderable and 12.0
to 15.0
for renderable. Your results may vary, so you can check this. I believe the font size has an effect on the output as well measureText()
, so keep that in mind.
Overall I'm not sure if this is a great solution, but this is the best I've come up with so far.
source to share
check the source code of the Googles Mozc project. The EmojiRenderableChecker class works really well! https://github.com/google/mozc/blob/master/src/android/src/com/google/android/inputmethod/japanese/emoji/EmojiRenderableChecker.java
it is similar to the compatible version for Paint.hasGlypgh (added in Marshmallow). https://developer.android.com/reference/android/graphics/Paint.html#hasGlyph(java.lang.String)
source to share