Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 检查拼写检查器是否打开?_Android_Spell Checking - Fatal编程技术网

Android 检查拼写检查器是否打开?

Android 检查拼写检查器是否打开?,android,spell-checking,Android,Spell Checking,我在我的Android应用程序中使用拼写检查器。如果在语言和输入设置中禁用,则应用程序崩溃。应用程序需要打开才能正常工作 是否有一种方法可以在使用它之前进行检查,以验证拼写检查程序是否已打开或直接从代码中打开它?您只需检查SpellCheckerSession的实例是否为null,并相应地决定Spellchecker是否已打开: 代码段: final TextServicesManager tsm = (TextServicesManager) getSystemService(Context.

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


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

您只需检查
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
    }
}

希望能有帮助ツ

你想禁用拼写更正吗?如果没有,那么发布错误日志否我想检查它是开还是关。还有一种方法可以打开它。
如果在语言和输入设置中关闭,则应用程序崩溃。
显示崩溃日志异常发送输入事件。MessageQueue回调中的异常:HandlerReceiveCallback E/MessageQueue JNI(6238):java.lang.NullPointerException:尝试调用空对象引用上的虚拟方法“void android.view.textservice.SpellCheckerSession.getSuggestions(android.view.textservice.TextInfo,int)”,在调用getSuggestions之前检查其是否为空