【问题标题】:Android Emoji Support Library not rendering Emojis on all the devicesAndroid 表情符号支持库未在所有设备上呈现表情符号
【发布时间】:2017-11-22 12:49:15
【问题描述】:

为了在我们的应用程序中支持Emojis,我们使用Downloadable fonts,如下面的guide 所述。我们正在使用Emoji Support Library version 26.0.0。该库的init代码如下。

private void initEmoji() {
    final FontRequest fontRequest = new FontRequest(
        "com.google.android.gms.fonts",
        "com.google.android.gms",
        "Noto Color Emoji Compat",
        R.array.com_google_android_gms_fonts_certs);
    EmojiCompat.Config config = new 
    FontRequestEmojiCompatConfig(getApplicationContext(), fontRequest)
    .setReplaceAll(true)
    .registerInitCallback(new EmojiCompat.InitCallback() {
      @Override
      public void onInitialized() {
        Log.i(NewsHuntAppController.class.getSimpleName(), "EmojiCompat initialized");
      }

      @Override
      public void onFailed(@Nullable Throwable throwable) {
        Log.e(NewsHuntAppController.class.getSimpleName(), "EmojiCompat initialization failed",
            throwable);
      }
    });
EmojiCompat.init(config);
}

我们在两台设备上测试了表情符号。第一个设备是 Android KitKat,第二个设备是 Android Nougat 设备。这两种设备都具有相同的 google play 服务版本。我们观察到大多数 Emoji 在两种设备上的渲染都是相同的,但很少有 Emoji 在 Android Nougat 上加载,而在 Android KitKat 上则没有。

以下是未在 Android KitKat 上加载的示例表情符号。

????????????????????????

理想情况下,如果两个设备具有相同的 google play 服务版本,那么应该在两个设备上呈现表情符号。但这并没有发生。如果有人知道这是什么原因,请告知。

【问题讨论】:

  • ???????????????????????????只有当他们缺少表情符号时才会出现这种情况
  • 但是由于我们使用的是支持兼容库,所以这不应该发生,对吧?
  • 查看 android 文档以了解支持问题
  • 在android文档中没有找到问题,所以在这里发布。
  • 我们有同样的问题。到目前为止有什么解决方案吗?

标签: android emoji


【解决方案1】:

使用最新版本的支持库,开发人员可以控制 EmojiCompat 是否会在没有变体选择器的情况下呈现,以及该规则的例外情况。请参阅: https://developer.android.com/reference/android/support/text/emoji/EmojiCompat.Config.html#setUseEmojiAsDefaultStyle(boolean)

? (https://emojipedia.org/emoji/%F0%9F%96%A5/) 是一个表情符号,默认为“文本呈现”。这意味着当仅存在 U+1F5A5 时,标准表示建议在文本呈现中呈现它(符号种类)。

这就是 EmojiCompat 不接受它作为表情符号的原因。目前,要让 EmojiCompat 接受它作为表情符号,您必须将特定代码点与 Emoji Variation Selector(U+FE0F) 一起使用。即 U+1F5A5 U+FE0F

【讨论】:

    【解决方案2】:

    因此,根据@Siyamed 的回答,解决方案是无论如何添加U+FE0F。

    代码如下所示:

    private static int[] fix(int... ary) {
        if (ary[ary.length - 1] == 0xfe0f) return ary;
        int[] result = Arrays.copyOf(ary, ary.length + 1);
        result[ary.length] = 0xfe0f;
        return result;
    }
    ...
    int[] codePoints = fix(0x1f1fe, 0x1f1ea); // <- just a example, I added it to all emojis 
    String emoji = new String(codePoints, 0, codePoints.length);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-10
      • 2016-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-17
      • 2014-01-20
      相关资源
      最近更新 更多