Sunday, January 27, 2019

New keyboard app not listed in Language & input settings page


I downloaded and imported Android SDK's Softkeyboard example (an app) to Android studio and installed it into my Sony xPeria Z3 running Android 5.1.1. That said, I do not see the app name in Language & input settings page.



I checked the list of installed apps on my phone and I see that SoftKeyboard is installed and in Android Studio, there is no error.


Can you show me a way to fix this problem?



Answer



Note: the commands in this solution requires setup in PC and the solution is tested on Android 4.2.1, 5.0.2 and 5.1.1.




Whenever an app equipped with an IME service is installed in the system, in order to connect its IME to the system, the device's owner must explicitly allow the app to become part of enabled input methods.


So how does it happen? We know that we can use command-line but that's not what ordinary users do.


It happens this way. When you launch that app, you're or would be asked to enable its keyboard. You are then redirected to a sub-activity of Settings app. In ROMs close to stock Android, a user can access that sub-activity from Settings → Language & input → Current Keyboard → Choose Keyboards. This is how it looks like in some devices:


(Click image to enlarge; image courtesy of OP)


IMG:



You can use command-line as an alternative to show that sub-activity


adb shell am start -a android.settings.INPUT_METHOD_SETTINGS
adb shell "am start 'intent:#Intent;action=android.settings.INPUT_METHOD_SETTINGS;end'" # alternative to above command

For an app, the moment you turn the slider towards right in that sub-activity, its IME's id is appended into the value of enabled_input_methods - a secure setting. The app then gets listed under Settings → Language & input, among those already enabled as input methods.


Since only one IME can remain as a default IME in system, the app then shows you a dialog to select a keyboard app as default. That dialog can be accessed from Settings → Language & input → Current Keyboard. Whatever entry you choose there becomes the default keyboard in the device.


Now that you know the details, you can now easily add a keyboard into enabled input methods, including your example keyboard app.





There's an another way too. All the enabled input methods can be listed by this command:



adb shell ime list -s

Example output


com.android.inputmethod.latin/.LatinIME
net.zhdev.ctrlvkeyboard/.CtrlVKeyboard

All the available (enabled or not) IME services can be listed through


adb shell ime list -a

Example output




com.android.inputmethod.latin/.LatinIME:
mId=com.android.inputmethod.latin/.LatinIME mSettingsActivityName=com.android.inputmethod.latin.settings.SettingsActivity
mIsDefaultResId=0x7f070000
Service:
priority=0 preferredOrder=0 match=0x108000 specificIndex=-1 isDefault=false
ServiceInfo:
name=com.android.inputmethod.latin.LatinIME
packageName=com.android.inputmethod.latin
labelRes=0x7f08003a nonLocalizedLabel=null icon=0x0 banner=0x0

enabled=true exported=true processName=com.android.inputmethod.latin
permission=android.permission.BIND_INPUT_METHOD
flags=0x0
net.zhdev.ctrlvkeyboard/.CtrlVKeyboard:
mId=net.zhdev.ctrlvkeyboard/.CtrlVKeyboard mSettingsActivityName=null
mIsDefaultResId=0x0
Service:
priority=0 preferredOrder=0 match=0x108000 specificIndex=-1 isDefault=false
ServiceInfo:
name=net.zhdev.ctrlvkeyboard.CtrlVKeyboard

packageName=net.zhdev.ctrlvkeyboard
labelRes=0x7f0b0015 nonLocalizedLabel=null icon=0x0 banner=0x0
enabled=true exported=true processName=net.zhdev.ctrlvkeyboard
permission=android.permission.BIND_INPUT_METHOD
flags=0x0
com.touchtype.swiftkey/com.touchtype.KeyboardService:
mId=com.touchtype.swiftkey/com.touchtype.KeyboardService mSettingsActivityName=com.touchtype.settings.TouchTypeKeyboardSettings
mIsDefaultResId=0x0
Service:
priority=0 preferredOrder=0 match=0x108000 specificIndex=-1 isDefault=false

ServiceInfo:
name=com.touchtype.KeyboardService
packageName=com.touchtype.swiftkey
enabled=true exported=true processName=com.touchtype.swiftkey
permission=android.permission.BIND_INPUT_METHOD
flags=0x0

The highlighted strings next to mId= are the IDs of the keyboard apps available in my system.


In any ID, the string before / is the package name of the keyboard app. Example: for Swiftkey keyboard, the mId is:


com.touchtype.swiftkey/com.touchtype.KeyboardService


The string com.touchtype.swiftkey is the package name of Swiftkey app. Package name is what will help you to find the appropriate mID that you should use to enable a particular keyboard app.


To know the package name of an app, follow View app's full package name?


In order to add or remove an IME into enabled input methods, do


# replace ID with mId of the keyboard app which you want to add or remove

adb shell ime enable ID
adb shell ime disable ID

To make an IME the default IME of the system, do



# Note that it doesn't matter whether the IME is added into enabled input methods or not. Consider this a direct override.

adb shell settings put secure default_input_method "ID"
adb shell content update --uri content://settings/secure --bind value:s:"ID" --where "name='default_input_method'" # alternative to above command

No comments:

Post a Comment

samsung galaxy s 2 - Cannot restore Kies backup after firmware upgrade

I backed up my Samsung Galaxy S2 on Kies before updating to Ice Cream Sandwich. After the upgrade I tried to restore, but the restore fails ...