我想要做类似的事情。我提出的解决方案是使用SpellCheckerSession,并检查它是否与onGetSentenceSuggestions中的完全匹配。
public class SpellChecker implements SpellCheckerSessionListener {
public SpellChecker(Activity a)
{
final TextServicesManager tsm = (TextServicesManager) a.getSystemService(
Context.TEXT_SERVICES_MANAGER_SERVICE);
SpellCheckerSession scs = tsm.newSpellCheckerSession(null, null, this, true);
TextInfo[] tia = {new TextInfo("trewgjj"), new TextInfo("great")};
scs.getSentenceSuggestions(tia, 3);
}
@Override
public void onGetSuggestions(SuggestionsInfo[] results) {
// TODO Auto-generated method stub
}
@Override
public void onGetSentenceSuggestions(SentenceSuggestionsInfo[] results) {
for (int i = 0; i < results.length; ++i) {
// Returned suggestions are contained in SuggestionsInfo
for (int j = 0; j < results[i].getSuggestionsCount(); ++j) {
SuggestionsInfo si = results[i].getSuggestionsInfoAt(j);
if ((si.getSuggestionsAttributes() & SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY) != 0)
Log.d("", "EXACT MATCH FOUND");
}
}
}
}
唯一的问题是,如果你也想验证对用户定义的字典中的单词。我不相信这些拼写检查框架中包含这些内容,因此您可能需要手动检查这些词语。