操作输入法设置后返回活动

问题描述 投票:0回答:3

我正在制作一个自定义键盘应用程序。
有一个按钮可引导用户从应用程序转到

Input Method Settings

意图如下:

startActivityForResult(new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS), 2000);

现在,有没有办法让用户在启用键盘后返回到 Activity?
编辑
当用户单击警告窗口上的“确定”按钮时,有没有办法设置广播接收器并注册?然后应用程序可以调用 super.onResume() 来恢复 Activity。

android android-intent android-softkeyboard android-input-method
3个回答
3
投票

因此,我只是生成一个 IntentService,它在启动“设置”菜单的同时侦听更改。我相信 SwiftKey 也是这样做的。

public class MyService extends IntentService {

    /**
     * Creates an IntentService
     */
    public MyService() {
        super("MyService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        String packageLocal = getPackageName();
        boolean isInputDeviceEnabled = false;
        while(!isInputDeviceEnabled) {
            InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
            List<InputMethodInfo> list = inputMethodManager.getEnabledInputMethodList();

            // check if our keyboard is enabled as input method
            for(InputMethodInfo inputMethod : list) {
                String packageName = inputMethod.getPackageName();
                if(packageName.equals(packageLocal)) {
                    isInputDeviceEnabled = true;
                }
            }
        }

        // open activity
        Intent newIntent = new Intent(this, MainActivity.class);
        newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(newIntent);
    }
}

3
投票
startActivityForResult(new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).addFlags
                (Intent.FLAG_ACTIVITY_CLEAR_TASK), 2000);

这应该可行,但请注意

Intent.FLAG_ACTIVITY_CLEAR_TASK
重新查询> = 11 api级别


0
投票

您可以添加 onResume() 侦听器,当用户转到激活键盘的设置时,您将任何布尔变量激活为 true,当用户返回到您的应用程序时, onResume() 侦听器命中,然后检查您的布尔变量是否为 true意味着用户进入设置来激活键盘,然后检查键盘是否处于活动状态并执行您的逻辑

© www.soinside.com 2019 - 2024. All rights reserved.