【发布时间】:2012-12-31 12:11:46
【问题描述】:
是否可以知道用户正在使用的键盘?如何检查用户是否使用 Swype 键盘?
【问题讨论】:
是否可以知道用户正在使用的键盘?如何检查用户是否使用 Swype 键盘?
【问题讨论】:
您可以使用以下方法检索当前的默认键盘:
String currentKeyboard = Settings.Secure.getString(getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
对于各种键盘,您将获得类似com.touchtype.swiftkey/com.touchtype.KeyboardService 的结果。第一部分是键盘的主包名,第二部分是它使用的Keyboard Service的名称。只需解析这个字符串,看看它是否与 Swype 的信息匹配(我现在只能提供 SwiftKey 的详细信息,因为我没有安装 Swype)。
【讨论】:
【讨论】:
以下内容可让您确定是否使用三星、Google 或 Swype 键盘。
public boolean usingSamsungKeyboard(Context context){
return usingKeyboard(context, "com.sec.android.inputmethod/.SamsungKeypad");
}
public boolean usingSwypeKeyboard(Context context){
return usingKeyboard(context, "com.nuance.swype.input/.IME");
}
public boolean usingGoogleKeyboard(Context context){
return usingKeyboard(context, "com.google.android.inputmethod.latin/com.android.inputmethod.latin.LatinIME");
}
public boolean usingKeyboard(Context context, String keyboardId)
{
final InputMethodManager richImm =
(InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
boolean isKeyboard = false;
final Field field;
try
{
field = richImm.getClass().getDeclaredField("mCurId");
field.setAccessible(true);
Object value = field.get(richImm);
isKeyboard = value.equals(keyboardId);
}
catch (IllegalAccessException e)
{
}
catch (NoSuchFieldException e)
{
}
return isKeyboard;
}
【讨论】: