gpt4 book ai didi

android - 检查拼写检查器是否打开?

转载 作者:搜寻专家 更新时间:2023-11-01 08:46:46 25 4
gpt4 key购买 nike

我在我的 Android 应用程序中使用拼写检查器。如果在语言和输入设置中关闭,则应用程序会崩溃。它需要打开才能使应用程序正常工作。

有没有一种方法可以在使用它之前进行检查以验证拼写检查器是否已打开或直接从代码中打开它?

最佳答案

您可以简单地检查 SpellCheckerSession 的实例是否为 null 并相应地决定 Spellchecker 是否打开:

代码 fragment :

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

希望能帮到你

关于android - 检查拼写检查器是否打开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27498612/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com