4

我正在使用 SDK 中的示例代码作为示例编写拼写检查客户端。我有以下代码(不是实际实现,而是准确的示例表示)

public class HelloSpellChecker implements SpellCheckerSessionListener {
    private SpellCheckerSession mSpellCheckService;

    private void bindService() {
        final TextServicesManager tsm = (TextServicesManager) getSystemService(
            Context.TEXT_SERVICES_MANAGER_SERVICE);
        mSpellCheckService = tsm.newSpellCheckerSession(null, null, this, true);
    }        

    public void getSuggestions(String word) {
        mSpellCheckService.getSuggestions(new TextInfo("tgis"), 3);
    }

    @Override
    public void onGetSentenceSuggestions(final SentenceSuggestionsInfo[] arg0) {
        Log.d(TAG, "onGetSentenceSuggestions");
        // Process suggestions
    }
}

我想知道的是onGetSentenceSuggestions只会在我的应用程序调用时触发getSuggestions,还是会在系统服务收到请求时触发getSuggestions

如果是后者,确保我的应用只处理它请求的建议的最佳方法是什么?

4

1 回答 1

3

I would say Android system service listener is localized through the session in this case. onGetSentenceSuggestions method is fired by any request to getSuggestions method. However, you don't have to worry about processing suggestions which your app requested since the spellchecker session takes care of it. Your app only gets the suggestions requested by the session your app created to interact with the spell checker service. Hope this helps.

References:

于 2013-11-01T15:52:40.833 回答