Android - 确定InputMethod(自定义键盘)的调用应用
Android - Determine Calling Application of an InputMethod (Custom Keyboard)
我正在按照本指南实施自定义键盘:http://developer.android.com/guide/topics/text/creating-input-method.html
有没有一种方法可以从我的 KeyboardService 中 'connected' 哪个应用程序(=包 ID)到(哪个应用程序接收我发送的输入事件)?
奇怪,一天看6次,觉得这个话题比较有意思。好吧,无论如何,我找到了解决方案,如果有人需要的话,这里是代码。
从 InputMethodService
可以收到 InputBinding
:
private String getCallerPackageId() {
InputBinding binding = getCurrentInputBinding();
return getApplicationContext().getPackageManager().getNameForUid(binding.getUid());
}
我正在按照本指南实施自定义键盘:http://developer.android.com/guide/topics/text/creating-input-method.html
有没有一种方法可以从我的 KeyboardService 中 'connected' 哪个应用程序(=包 ID)到(哪个应用程序接收我发送的输入事件)?
奇怪,一天看6次,觉得这个话题比较有意思。好吧,无论如何,我找到了解决方案,如果有人需要的话,这里是代码。
从 InputMethodService
可以收到 InputBinding
:
private String getCallerPackageId() {
InputBinding binding = getCurrentInputBinding();
return getApplicationContext().getPackageManager().getNameForUid(binding.getUid());
}