final TextServicesManager tsm = (TextServicesManager) getSystemService( Context.TEXT_SERVICES_MANAGER_SERVICE); spellCheck = tsm.newSpellCheckerSession(null, Local.ENGLISH, this, false);
@Override protected void onResume() { super.onResume(); final TextServicesManager tsm = (TextServicesManager) getSystemService( Context.TEXT_SERVICES_MANAGER_SERVICE); spellCheckerSession = tsm.newSpellCheckerSession(null, null, this, true); }
final TextServicesManager tsm = (TextServicesManager) getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE); scs = tsm.newSpellCheckerSession(null, null, this, true); if (scs != null) { scs.getSuggestions(new TextInfo(text.getText().toString()), 3); } else { // Show the message to user Toast.makeText(this, "Please turn on the spell checker from setting", Toast.LENGTH_LONG).show(); // You can even open the settings page for user to turn it ON ComponentName componentToLaunch = new ComponentName("com.android.settings", "com.android.settings.Settings$SpellCheckersSettingsActivity"); Intent intent = new Intent(); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setComponent(componentToLaunch); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { this.startActivity(intent); } catch (ActivityNotFoundException e) { // Error } }
/** * Constructs a SpellCheckerSessionBridge object as well as its SpellCheckerSession object. * @param nativeSpellCheckerSessionBridge Pointer to the native SpellCheckerSessionBridge. */ private SpellCheckerSessionBridge(long nativeSpellCheckerSessionBridge) { mNativeSpellCheckerSessionBridge = nativeSpellCheckerSessionBridge; Context context = ContextUtils.getApplicationContext(); final TextServicesManager textServicesManager = (TextServicesManager) context.getSystemService( Context.TEXT_SERVICES_MANAGER_SERVICE); // This combination of parameters will cause the spellchecker to be based off of // the language specified at "Settings > Language & input > Spell checker > Language". // If that setting is set to "Use system language" and the system language is not on the // list of supported spellcheck languages, this call will return null. This call will also // return null if the user has turned spellchecking off at "Settings > Language & input > // Spell checker". mSpellCheckerSession = textServicesManager.newSpellCheckerSession(null, null, this, true); }
/** * Main initialization of the input method component. Be sure to call * to super class. */ @Override public void onCreate() { super.onCreate(); mInputMethodManager = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE); mWordSeparators = getResources().getString(R.string.word_separators); final TextServicesManager tsm = (TextServicesManager) getSystemService( Context.TEXT_SERVICES_MANAGER_SERVICE); mScs = tsm.newSpellCheckerSession(null, null, this, true); }
/** * Main initialization of the input method component. Be sure to call * to super class. */ @Override public void onCreate() { super.onCreate(); mInputMethodManager = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE); mWordSeparators = getResources().getString(R.string.word_separators); final TextServicesManager tsm = (TextServicesManager) getSystemService( Context.TEXT_SERVICES_MANAGER_SERVICE); mScs = tsm.newSpellCheckerSession(null, null, this, true); }
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"); } } } }