我正在使用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
请求时触发?
如果是后者,确保我的应用仅处理它请求的建议的最佳方法是什么?
我会说Android系统服务侦听器是通过会话本地化的。onGetSentenceSuggestions 方法由任何请求 getSuggestions 方法触发。但是,您不必担心处理应用请求的建议,因为拼写检查器会话会处理它。你的应用仅获取你的应用创建的会话请求的建议,以便与拼写检查器服务进行交互。希望这有帮助。
引用:
- http://developer.android.com/reference/android/view/textservice/SpellCheckerSession.html
- http://developer.android.com/guide/topics/text/spell-checker-framework.html