如何将 InputMethodService 与服务连接?
How to connect InputMethodService with a Service?
我想将扩展 InputMethodService 的自定义软键盘与另一个服务连接。我需要从通用服务调用我的软键盘中的方法。
问题是我无法扩展 Binder class 因为 onBind() 方法在 AbstractInputMethodService 中定义为 final...
现在,如何从其他服务调用我的软键盘 class 中的方法?
我已经使用广播接收器解决了这个问题class。
class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("GET_KEY_KEY")) {
String msg = intent.getStringExtra("msg");
InputConnection ic = getCurrentInputConnection();
if (ic != null) {
ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_RIGHT));
}
}
}
}
然后我向我的服务发送了一个广播。
Intent intent = new Intent();
intent.setAction("GET_KEY_KEY");
sendBroadcast(intent);
我想将扩展 InputMethodService 的自定义软键盘与另一个服务连接。我需要从通用服务调用我的软键盘中的方法。
问题是我无法扩展 Binder class 因为 onBind() 方法在 AbstractInputMethodService 中定义为 final...
现在,如何从其他服务调用我的软键盘 class 中的方法?
我已经使用广播接收器解决了这个问题class。
class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("GET_KEY_KEY")) {
String msg = intent.getStringExtra("msg");
InputConnection ic = getCurrentInputConnection();
if (ic != null) {
ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_RIGHT));
}
}
}
}
然后我向我的服务发送了一个广播。
Intent intent = new Intent();
intent.setAction("GET_KEY_KEY");
sendBroadcast(intent);