On Android, I want to check programmatically if the InputMethod provided by my application is the current activated input method, or not.
Currently, I use a trick : detect whether my InputMethodService is started or not.
public boolean isInputMethodEnabled() {
ActivityManager activityManager = (ActivityManager).getSystemService(ACTIVITY_SERVICE);
List<RunningServiceInfo> servicesInfo = activityManager.getRunningServices(Integer.MAX_VALUE);
for (RunningServiceInfo serviceInfo : servicesInfo) {
if (MyInputMethodService.class.getName().equals(serviceInfo.service.getClassName())) {
return true;
}
}
return false;
}
This works well in general, but fails when the app is updated : my input method is still selected, but the service is not started yet. The service will be started when a keyboard is required for the first time, and until then isInputMethodEnabled() will return false.
So my question is : do you know another way to check if my input method is selected, or do you know a way to restart the input method service after an update, without having to show a textview ?
I found my answer on another Stack Overflow question :
Android: Determine active input method from code
The following code (updated) did the trick :