Android – detects whether the input method is selected
•
Android
In my application, I need to let the user select an input method. Once it is selected, I should perform some tasks. How to detect that the user actually selects inputmethod?
This is the code used to display the inputmethod list
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();
}
resolvent:
Unfortunately, you cannot capture the input method selected by the user in inputmethod picker
However, you can use broadcastreceiver to check after user selection. When ime changes, intent.action will be broadcast_ 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.*/
}
}
}
Then, register it
IntentFilter filter = new IntentFilter(Intent.ACTION_INPUT_METHOD_CHANGED);
registerReceiver(mReceiver, filter);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码