检查拼写检查是否已开启?

时间:2014-12-16 06:12:19

标签: android spell-checking

我在Android应用中使用拼写检查器。如果在语言和输入设置中关闭,则应用程序崩溃。需要启动才能让App正常运行。

有没有办法在使用之前我可以检查以确认拼写检查器是打开还是直接从代码打开?

1 个答案:

答案 0 :(得分:3)

您只需检查SpellCheckerSession null的实例,然后相应地决定Spellchecker是否开启:

代码段:

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
    }
}

希望它有助于ツ

相关问题