我試圖顯示手機上當前安裝的所有輸入法列表。我做這個越來越InputMethodInfo對象的列表:如何獲取手機上安裝的所有輸入法(及其名稱)的列表?
InputMethodManager imeManager = (InputMethodManager)getApplicationContext().getSystemService(INPUT_METHOD_SERVICE);
List<InputMethodInfo> InputMethods = imeManager.getEnabledInputMethodList();
這工作,但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) { }
有沒有人知道如何做到這一點?我不在乎我該怎麼做,我只需要能夠生成輸入法列表,因爲它們出現在手機的「語言和鍵盤」菜單中,然後存儲用戶的選擇。我想也許我可以使用InputMethodManager來啓動標準的輸入法選擇菜單,然後通過查看菜單關閉後當前選擇哪個IME來查看用戶選擇了哪一個,但是據我所知,無法看到系統中當前選擇了IME。