Reputation: 592
I am using Spell Checker in my Android App. If is is off in the Language and Input settings then the App crashes. It needs to be on for the App to work properly.
Is there a way where before using it I can place a check to verify that is the spell checker is on or turn it on directly from code?
Upvotes: 2
Views: 890
Reputation: 7306
You can simply check the instance of SpellCheckerSession
for null
and accordingly decide whether Spellchecker
is turned ON or not:
Code Snippet:
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
}
}
Hope it helps ツ
Upvotes: 3