che*_*gon 3 methods android input ime
我正在尝试显示当前安装在手机上的所有输入法的列表.我通过这样做得到一个InputMethodInfo对象的列表:
InputMethodManager imeManager = (InputMethodManager)getApplicationContext().getSystemService(INPUT_METHOD_SERVICE);
List<InputMethodInfo> InputMethods = imeManager.getEnabledInputMethodList();
Run Code Online (Sandbox Code Playgroud)
这有效,但InputMethodInfo对象在任何地方都没有友好名称.例如,它代替"Swype",它会给我"com.swype.android.inputmethod.SwypeInputMethod"
这不是向用户显示列表的非常友好的方式,并且这些包名称不遵循严格的模式,因此我无法可靠地从类名称中解析键盘名称.
我甚至试图得到真正的幻想,并获得InputMethodInfo的相应ServiceInfo对象,以便我可以解析其标签资源整数,但我每次运行时都会得到NameNotFoundExceptions.
ComponentName componentName = inputMethodInfo.getComponent();
ServiceInfo serviceInfo = packageManager.getServiceInfo(componentName, 0);
Resources resources = getResources();
try
{
String imeServiceLabel = resources.getString(serviceInfo.labelRes);
}
catch (NameNotFoundException e) { }
Run Code Online (Sandbox Code Playgroud)
有人知道怎么做到这一点吗?我不在乎如何做,我只需要能够生成一个输入方法列表,因为它们出现在手机的语言和键盘菜单中,然后存储用户的选择.我想也许我可以使用InputMethodManager启动标准输入法选择菜单,然后通过查看菜单关闭后当前选择的IME来查看用户选择了哪一个,但据我所知,没有办法看到当前在系统中选择了哪个IME.
当它在我的鼻子底下时,我浪费了很多时间.在我做其他事情时,我发现了自己问题的答案.这将通过常规InputMethodInfo对象为您提供输入法的友好名称.
inputMethodInfo.loadLabel(packageManager).toString();
我已经习惯于编写C#,其中所有内容都是作为属性实现的,所以我通过在运行时查看对象属性来完成大部分调查.但是,Java通过公共方法提供了大部分此类信息,而我刚刚在Eclipse中弹出自动完成框时就注意到了这一点.
归档时间: |
|
查看次数: |
3928 次 |
最近记录: |