5

I would like to support emojis for Huawei devices in my app. For all other vendors I use code like this to init EmojiCompat:

 val fontRequest = FontRequest(
            "com.google.android.gms.fonts",
            "com.google.android.gms",
            "Noto Color Emoji Compat",
            R.array.com_google_android_gms_fonts_certs
        )
        val config = FontRequestEmojiCompatConfig(context, fontRequest)
        EmojiCompat.init(config)

But for Huawei devices, for they do not have access to google resources (my guess), it does not work, and EmojiCompat doesn't get initialized. I know that BundledEmojiCompatConfig could be used, but I would prefer always to fetch the newest font.

Is there any alternative to Google's providerAuthority/Package for Huawei devices?

Jan Stoltman
  • 394
  • 3
  • 15
  • 1
    I was searching for HMS AppConnect and HMS Core documentation for anything on `Font` and `FontRequest`, seem they don't have any service.You should roll with bundling. – Nikola Despotoski Jan 14 '21 at 09:46
  • That's unlucky. I guess that Huawei's ecosystem is not there yet. Thanks for your answer! – Jan Stoltman Jan 14 '21 at 09:49
  • What specific error did you get? And on which device model? I just tested this sample https://github.com/android/user-interface-samples/tree/main/EmojiCompat on a Huawei Mate 30 Pro ( without Google services ) and it's working – GioLaq Jan 20 '21 at 10:33

2 Answers2

2

You can use the BundledEmojiCompatConfig for devices having no access to GMS.

For example:

  1. Add dependency:
def emojiCompatVersion = "1.0.0-rc01"

implementation 'androidx.emoji2:emoji2-views:$emojiCompatVersion'
implementation 'androidx.emoji2:emoji2-bundled:$emojiCompatVersion'
  1. Helper Class to Initialize EmojiCompat
import android.content.Context
import androidx.emoji2.bundled.BundledEmojiCompatConfig
import androidx.emoji2.text.EmojiCompat
import androidx.emoji2.text.EmojiCompat.LOAD_STRATEGY_MANUAL

object EmojiCompatHandler {

    fun initializeEmojiCompat(appContext: Context) {
        val config = BundledEmojiCompatConfig(appContext)
            .setReplaceAll(true)
            .setMetadataLoadStrategy(LOAD_STRATEGY_MANUAL)
            .registerInitCallback(object : EmojiCompat.InitCallback() {
                override fun onInitialized() {
                    logDebug("EmojiCompat Initialized Successfully")
                }

                override fun onFailed(throwable: Throwable?) {
                    logDebug("EmojiCompat Failed to Load: ${throwable?.message}")
                }
            })

        EmojiCompat.init(config)
    }
}

  1. Initialize EmojiCompat as early as possible (can be pretty slow from what I've observed),
    either via Application#onCreate() or App Startup
    (https://developer.android.com/topic/libraries/app-startup)
Darshan
  • 4,020
  • 2
  • 18
  • 49
0

EmojiCompat is part of Android and is not exclusive to Google Mobile Services. I tested the below demo app that has the same code snippet as yours, and it works fine on my Huawei Mate 30 Pro.

Github link.

Zinna
  • 1,947
  • 2
  • 5
  • 20
  • And what about "You need the beta version of Google Play Services to use this feature" part? Not all Huawei devices, especially not the new ones, come with any Google related packages – Jan Stoltman Mar 09 '21 at 07:53
  • Can you provide more information on this issue? I did not receive this message when I was tested EmojiCompat. It shouldn't give any Google-related errors at all, as it is an Android component. – Zinna Mar 09 '21 at 20:30