android – 检测是否已选择输入法
作者:互联网
在我的应用程序中,我需要让用户选择一个输入法.一旦它被选中,我应该执行一些任务.如何检测到用户实际选择了InputMethod?
这是用于显示InputMethod列表的代码.
InputMethodManager imeManager = (InputMethodManager) mw.getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imeManager != null) {
imeManager.showInputMethodPicker();
} else {
Toast.makeText(mw.getApplicationContext(), "IME ERROR",
Toast.LENGTH_LONG).show();
}
解决方法:
遗憾的是,您无法捕获用户在InputMethodPicker中选择的输入法.
但是,您可以在用户选择后使用BroadcastReceiver进行检查.
当IME更改时,将广播Intent.ACTION_INPUT_METHOD_CHANGED.
public class InputMethodChangeReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(Intent.ACTION_INPUT_METHOD_CHANGED)) {
.....
/* You can check the package name of current IME here.*/
}
}
}
然后,注册它.
IntentFilter filter = new IntentFilter(Intent.ACTION_INPUT_METHOD_CHANGED);
registerReceiver(mReceiver, filter);
标签:android,android-input-method 来源: https://codeday.me/bug/20190712/1441867.html