Spell checker settings intent Android

2019-06-28 00:48发布

In Android, I can launch the Keyboard & Input Settings dialog using the ACTION_INPUT_METHOD_SETTINGS intent:

getPresenter().startActivity(new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS));

Question: How can I open the "Spell Checker" settings dialog (available in Jelly Bean+) so that the user can enable my service?

Example: I can get to it from the Language & Input settings: Language and input settings

But I want to take the user directly to this screen: Spell Checker settings

2条回答
Luminary・发光体
2楼-- · 2019-06-28 01:38

Here you go:

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) {
            //TODO
        }

You can find out the names of other Activities by starting the Activity and lookup the Intent used in Logcat. The output for me was:

I/ActivityManager(  589): START u0 {act=android.intent.action.MAIN cmp=com.android.settings/.Settings$SpellCheckersSettingsActivity} from pid 13084
查看更多
放我归山
3楼-- · 2019-06-28 01:48

Yes, It is Possible..:)

Intent intent = new Intent();
intent.setComponent(new ComponentName("com.android.settings","com.android.settings.Settings$SpellCheckersSettingsActivity"));
startActivityForResult(intent);

We create an explicit intent, and we have to launch the com.android.settings.Settings$SpellCheckersSettingsActivity component. For Future Reference, You can use LogCat in eclipse to find whatever package or component you are trying to launch. Just look at the ActivityManager's Starting activity messages and you will see the package and component name of any Activity.

查看更多
登录 后发表回答