如何将 InputMethodService 与服务连接?

我想将扩展 InputMethodService 的自定义软键盘与另一个服务连接。我需要从通用服务调用我的软键盘中的方法。

问题是我无法扩展 Binder 类,因为 onBind() 方法在 AbstractInputMethodService 中定义为 final ...

现在,如何从其他服务调用我的 SoftKeyboard 类中的方法?


冉冉说
浏览 90回答 1
1回答

慕运维8079593

我已经通过使用广播接收器类解决了这个问题。    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);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java