简体   繁体   中英

How to implement correction suggestions without Spell checker framework?

I use Spell checker framework to display suggestions on my custom Android keyboard. I works fine, but not on Samsung devices. How I can fix this, use another way or may be some library?

My code

val spellCheckerSession =
    (context.getSystemService(TEXT_SERVICES_MANAGER_SERVICE) as TextServicesManager)
        .newSpellCheckerSession(
            null,
            Locale.ENGLISH,
            object : SpellCheckerSession.SpellCheckerSessionListener {
                override fun onGetSuggestions(p0: Array<out SuggestionsInfo>?) {}

                override fun onGetSentenceSuggestions(sentenceSuggestionsInfos: Array<out SentenceSuggestionsInfo>?) {
                    // TODO use suggestions
                }
            },
            true
        )
spellCheckerSession?.getSentenceSuggestions(
    arrayOf(TextInfo(inputWord)),
    SUGGESTION_COUNT
)

Spell checker is generally used by non-keyboards to offer spelling corrections. Keyboard generally just automatically correct things, or offer options in their candidates view (and they may use the candidates view API for that or they may just make their own candidates view above the keyboard. I know at Swype we did the second, because we didn't like how the built in candidate functionality behaved).

Actually I just remembered- it might be my fault it has problems on Samsung devices. A decade ago when the spell checker framework came out, it interacted badly with us and some of their other custom software. I suggested to their engineers they just disable the functionality, since all the keyboards they used had it built in. They did. They may never have changed that. Sorry about that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM