是否可以知道用户正在使用的键盘?如何检查用户是否使用 Swype 键盘?
问问题
2050 次
3 回答
13
您可以使用以下方法检索当前的默认键盘:
String currentKeyboard = Settings.Secure.getString(getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
您将获得与com.touchtype.swiftkey/com.touchtype.KeyboardService
各种键盘类似的结果。第一部分是键盘的主包名,第二部分是它使用的Keyboard Service的名称。只需解析这个字符串,看看它是否与 Swype 的信息匹配(我现在只能提供 SwiftKey 的详细信息,因为我没有安装 Swype)。
于 2013-01-17T02:01:47.693 回答
2
于 2013-01-17T01:54:45.540 回答
1
以下内容可让您确定是否使用三星、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;
}
于 2019-08-26T15:14:01.003 回答