I was developing a custom keyboard with Android Studio, and although I made the keyboard itself, I couldn't find a way to determine the validity of the IME.
What I wanted to do was that a keyboard app would display an alert when the keyboard wasn't enabled in the app, jump to the settings, and try to enable the IME. right.
do not know?
... well, then it can't be helped.
I wanted to do that for the time being.
I will leave the code as a memorandum. By the way, I love the fact that I developed it with java instead of kotlin.
Let's take a look at the code immediately.
hoge.java
//Get a list of installed IME applications
InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
List<InputMethodInfo> inputMethodInfoList = imm.getEnabledInputMethodList();
for (int i = 0; i < inputMethodInfoList.size(); ++i) {
InputMethodInfo inputMethodInfo = inputMethodInfoList.get(i);
CharSequence label = inputMethodInfo.loadLabel(getPackageManager());
if(String.valueOf(label).equals("hoge_keyboard")) {
Log.v("label", String.valueOf(label) + " is active!");
}
}
Well, it looks like this. I'm just a beginner who just started developing android, so there may be a better way.
The if statement is displayed in the log when the keyboard name matches hoge_keyboard
. It's okay if you can change the name you want to match and the content of the if statement according to your code.
I hope it helps people who are facing similar problems.
Recommended Posts