Determining if a custom keyboard is enabled in Android Studio (Java)

I made a custom keyboard, but I can't judge the validity!

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.

Actually it wasn't that difficult

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

Determining if a custom keyboard is enabled in Android Studio (Java)
What is a class in Java language (3 /?)
What is a class in Java language (1 /?)
What is a class in Java language (2 /?)
Java to C and C to Java in Android Studio
Memo: [Java] If a file is in the monitored directory, process it.
[Android / Java] Operate a local database in Room
I got a cannot resolve symbol in Android Studio
Output true with if (a == 1 && a == 2 && a == 3) in Java (Invisible Identifier)
Notes in Android studio
Java11: Run Java code in a single file as is
Refer to C ++ in the Android Studio module (Java / kotlin)
Use a JDK from another OpenJDK provider in Android Studio
Read WAV data as a byte array in Android Java
You are currently using Java 6. Solution in Android Studio Gradle
Find a subset in Java
Java in Visual Studio Code
I tried to create a simple map app in Android Studio
Source to display character array with numberPicker in Android studio (Java)
3 Implement a simple interpreter in Java
I created a PDF in Java.
How slow is a Java Scanner?
Automatically insert `@SuppressWarnings` in Android Studio
OkHttp3 (GET, POST) in Android Studio
Try an If expression in Java
[Android Studio] [Java] Learning memos & links
A simple sample callback in Java
What is a snippet in programming?
Java Calendar is not a singleton.
What is a lambda expression (Java)
Get stuck in a Java primer
Reintroducing Java 8 available from Android Studio 2.4
[Kotlin / Android] Create a custom view
[Java] Conditional branching is an if statement, but there is also a conditional operator.