I was wondering if there is a method that would allow me to detect from the keyboard container app whether the associated keyboard has been activated in the the device's Settings app.
For example, I am interested in adding a simple "steps" feature inside the container app where step 1 would be "activate the keyboard", and step 2 would be contingent on step 1's completion. As such, I am interested in figuring out whether there is a way to detect whether the keyboard extension is activated?
Thanks!
Here is a summary: Go to Android Settings > Languages and input > Current keyboard > Choose keyboards. You should see your Custom Keyboard on the list. Enable it.
Here is a method I have used in one of my projects. I think it is what you asked for, hope it helps you.
- (BOOL)isCustomKeyboardEnabled { NSString *bundleID = @"com.company.app.customkeyboard"; // Replace this string with your custom keyboard's bundle ID NSArray *keyboards = [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] objectForKey:@"AppleKeyboards"]; // Array of all active keyboards for (NSString *keyboard in keyboards) { if ([keyboard isEqualToString:bundleID]) return YES; } return NO; }
Just in case here is Swift version of Kurt's brilliant and awesome answer:
func isKeyboardExtensionEnabled() -> Bool { guard let appBundleIdentifier = Bundle.main.bundleIdentifier else { fatalError("isKeyboardExtensionEnabled(): Cannot retrieve bundle identifier.") } guard let keyboards = UserDefaults.standard.dictionaryRepresentation()["AppleKeyboards"] as? [String] else { // There is no key `AppleKeyboards` in NSUserDefaults. That happens sometimes. return false } let keyboardExtensionBundleIdentifierPrefix = appBundleIdentifier + "." for keyboard in keyboards { if keyboard.hasPrefix(keyboardExtensionBundleIdentifierPrefix) { return true } } return false }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With